Is there anyway in php to use alternation in a condition as part of a conditional statement? For example:
Imagine I had two backreferences "1" and "2" and needed to check whether either of them existed in order to carry out one of two patterns, like so
(?(1|2)foo|bar)
I'm using php 5.2.14 so don't have the benefit of escaping backreferences. Everytime I try anything remotely like this I get a compile error...
Is there any possible work-around or is it a case of doing a conditional within a conditional?
Regards
Chris
There is no syntax for this I know of. All you can do is:
(?(1)foo|(?(2)foo|bar))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With