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
Post a Comment