0

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

4
  • regex101 actually tells you which features are not supported in the JS regex engine. It's now about looking up how to do those in a different way, or if the syntax is different. Commented Mar 15, 2016 at 9:34
  • (?1) is a subroutine call not available in JS. Commented Mar 15, 2016 at 9:35
  • It depends on what you want to do with this regex Commented Mar 15, 2016 at 9:46
  • Invalid group, character '1' after '?' at column 23 as you can see if you input it into regen.io Commented Mar 15, 2016 at 9:54

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.