I have following regex expression which is not working in JQuery but working fine in php version
What am I doing wrong?
Expression
if\s*\(((?:[^\(\)]|\((?1)\))*+)\)\s*{((?:[^{}]|{(?2)})*+)}
I have following regex expression which is not working in JQuery but working fine in php version
What am I doing wrong?
Expression
if\s*\(((?:[^\(\)]|\((?1)\))*+)\)\s*{((?:[^{}]|{(?2)})*+)}
Regex is not a universal language. You are using some constructs only available in PHP/PCRE (see what I changed below) and not JavaScript.
This regex is about the same, working in either version: if\s*\(((?:[^\(\)]|\((\1)\))*)\)\s*{((?:[^{}]|{(\2)})*)}
(?1) becomes (\1) (same with 2)
*+ becomes *
Note: I removed the backtracking control sequence: *+, so I wouldn't be surprised if this catastrophically backtracks with some inputs.
(?1)is a subroutine call not available in JS.Invalid group, character '1' after '?' at column 23as you can see if you input it into regen.io