From: lucas_fnf@... Date: 2016-06-03T18:34:03+00:00 Subject: [ruby-core:75835] [Ruby trunk Bug#12452] Regexp alternation does not backtrack to check the other alternatives if a match is found on the first one Issue #12452 has been updated by Lucas Farias. ruby -v changed from 2.0.0 to 2.2.4 Didn't know that support for 2.0.0 was dropped, updated to 2.2.4, bug still present ---------------------------------------- Bug #12452: Regexp alternation does not backtrack to check the other alternatives if a match is found on the first one https://bugs.ruby-lang.org/issues/12452#change-59013 * Author: Lucas Farias * Status: Open * Priority: Normal * Assignee: * ruby -v: 2.2.4 * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- 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")` `=> #` `irb(main):002:0> /(abc|ab)(de|cedf)/.match("abcdef")` `=> #` -- https://bugs.ruby-lang.org/ Unsubscribe: