Project

General

Profile

Actions

Bug #22494

closed

Regexp search misses a match when an assertion precedes a leading .*

Bug #22494: Regexp search misses a match when an assertion precedes a leading .*

Added by mame (Yusuke Endoh) 14 days ago. Updated about 5 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127297]

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 Actions #1 [ruby-core:127298]

  • 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 Actions #2

  • 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 Actions #3 [ruby-core:127515]

  • Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE
Actions

Also available in: PDF Atom