Jankya
Jankya

Reputation: 958

PHP Regex doesn't work in JQuery

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)})*+)}

php link

Jquery Link

Upvotes: 0

Views: 65

Answers (1)

Laurel
Laurel

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)})*)}

What I changed

(?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

Related Questions