views:

85

answers:

1

Just a language feature question, I know there's plenty of ways to do this outside of regexes (or with multiple regexes).

Does ruby support conditional regular expressions? Basically, an IF-THEN-ELSE branch inside a regular expression, where the predicate for the IF is the presence (or absense) of a captured group in the expression.

In perl, the syntax is (?(predicate)yes-pattern|no-pattern) as in

/(?:y|(x))(?(1)y|x)/

I haven't been able to find any reference to anything like it in any ruby docs that I've browsed, but I figured I'd ask here to make sure, in case I was searching for the wrong words, or it was elided from the docs.

+2  A: 

No, ruby does not support that (neither in 1.8 nor 1.9).

sepp2k