Reputation: 958
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)})*+)}
Upvotes: 0
Views: 65
Reputation: 6173
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.
Upvotes: 1