Javascript Regex: create new a lookbehind regular expression with variable? -


i want create new regexp variable javascript. got trouble when want create new lookaround regexp:

var xvar = "_on"; var regex = new regexp("(?<!" + xvar + ")(.gif|.jpg|.png)$"); #=> syntaxerror: invalid regular expression: /(?<!_on)(.gif|.jpg|.png)$/: invalid group 

i tried escape special characters follow creating regexp special characters, can create new regexp string, not lookaround regex.

/\(\?<!_on\)\(\.gif\|\.jpg\|\.png\)\$/ 

can me?

i don't know goal of regexp quantifier (...) causes error in situation. example, use non-capturing parentheses (?:...).

var regex = new regexp("(?:<!" + xvar + ")(?:.gif|.jpg|.png)$"); 

refer to: regular expressions - javascript | mdn.

@alan moore: you're right.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -