Bug #12452
closedRegexp alternation does not backtrack to check the other alternatives if a match is found on the first one
Description
Hi, there is a problem with Regexps containing alternation where it returns the first matched alternative even if there is another alternative that would've resulted on a longer match, it's probably caused by not backtracking and checking the remaining alternatives.
If you have /a|ab/.match("ab") it returns just "a". Many discussions that I found on the internet suggested to whoever was making the complaint was just change the order of the alternatives so that it tests first the longer alternative, but for regular expressions like /(abc|ab)(de|cdef)/.match("abcdef") the alternative of the first alternation that would result on a longer match is the shorter one. And these examples don't even have repetition.
irb(main):001:0> /a|ab/.match("ab")
=> #<MatchData "a">
irb(main):002:0> /(abc|ab)(de|cedf)/.match("abcdef")
=> #<MatchData "abcde" 1:"abc" 2:"de">