A conditional match chooses between two regular-expression subexpressions according to whether a specified capture was found. Ruby supports numeric conditions such as (?(1)b|c) and named-capture conditions. section 11.5.3
Choose based on capture 1
The pattern /(a)?(?(1)b|c)/ matches "ab" because capture 1 contains "a"; it matches "c" when that optional capture is absent. It does not match "b", because the unmet condition selects the alternative "c". section 11.5.3
>> re = /(a)?(?(1)b|c)/
=> /(a)?(?(1)b|c)/
>> re.match("ab")
=> #<MatchData "ab" 1:"a"> 1
>> re.match("b")
=> nil 2
>> re.match("c")
=> #<MatchData "c" 1:nil> 3
Run the numeric conditional against all three strings and inspect the captured value in MatchData. section 11.5.3
/(?<first>a)?(?(<first>)b|c)/
Compare the numeric form with a named-capture condition using the first capture. section 11.5.3
