Interpolate A String Into A Regex
You can build up strings with concatenation or the template literal syntax. If you're incorporating variables as part of this string building, that's called interpolation.
But what if you need to interpolate variables into a regular expression (regex)?
A regex literal looks like this:
This works great for fixed strings, but won't cut it if you need to work variable strings.
What's needed to work with variables is the RegExp
constructor:
You can build up some string with string variables and regex syntax and new RegExp()
will turn it into a regex.
PreviousInstall The Latest Version Of Node With NvmNextISO-8601 Formatted Dates Are Interpreted As UTC
Last updated