I have a regular expression
var p = /\bj[^\b]*?\b/gi;
I need to make the ‘j’ a variable value, but when i do the following;-
var p = new RegExp('\\b'+'${0}'+'[^\\b]*?\\b', 'gi');
I get error –
Uncaught SyntaxError: Invalid regular expression: /\b${0}[^\b]*?\b/: Nothing to repeat
Any help appreciated.
Thank you
Sorry guys, I should have been more clear, the value ‘{0}’ is a token that will be replaced and not a variable. The error was occurring because ‘{‘ and ‘}’ are special characters in regular expressions.
So changing the token pattern fixed the problem