Actions
Bug #22494
closedRegexp search misses a match when an assertion precedes a leading .*
Bug #22494:
Regexp search misses a match when an assertion precedes a leading .*
Description
When a regexp starts with an assertion (^, \b, (?=...), (?!...)) followed by .*, the search only tries the start position and misses later matches.
"aab".index(/(?!a).*b/m) #=> nil (expected: 2)
"ab\ncb".index(/^.*b/m, 1) #=> nil (expected: 3)
"aaaa bx".index(/\b.*x/, 1) #=> nil (expected: 4)
@make_now_just (Hiroya Fujinami) found this and wrote the fix.
Updated by mame (Yusuke Endoh) 14 days ago
- Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED
Updated by make_now_just (Hiroya Fujinami) 7 days ago
- Status changed from Open to Closed
Applied in changeset git|dbfe6bac2285ea61a76a2dec970cf859f5a8fef4.
Do not treat a leading .* after an assertion as an implicit anchor
When an assertion such as ^, \b or a lookahead precedes the leading .*, it may fail at the start position and hold later, so the search must try later positions.
[Bug #22494]
Updated by k0kubun (Takashi Kokubun) about 5 hours ago
- Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE
ruby_4_0 85e6cd39a35f116d6c618309286594fbb5b40e37 merged revision(s) dbfe6bac2285ea61a76a2dec970cf859f5a8fef4.
Actions