Project

General

Profile

Actions

Bug #20097

open

Regexp#match? with empty capture group repeat is inconsistent

Added by tompng (tomoya ishida) 10 months ago. Updated 10 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +MN [arm64-darwin22]
[ruby-core:115931]

Description

It sometimes matches and sometimes does not, depend on repeat quantifier number.

# empty capture group repeat
p /(a(){1,4}){2}/.match?('aa') #=> true
p /(a(){1,5}){2}/.match?('aa') #=> false

# repeat of capture group that match to empty string
p /(a(|){1,2}){2}/.match?('aa') #=> true
p /(a(|){1,3}){2}/.match?('aa') #=> false
p /(a(x?y?|z){1,2}){2}/.match?('aa') #=> false

non-capturing group seems ok.

p /(a(?:){1,4}){2}/.match?('aa') #=> true
p /(a(?:){1,5}){2}/.match?('aa') #=> true
p /(a(?:|){1,2}){2}/.match?('aa') #=> true
p /(a(?:|){1,3}){2}/.match?('aa') #=> true
p /(a(?:x?y?|z){1,2}){2}/.match?('aa') #=> true

Same behavior in ruby 3.0, 3.1, 3.2

Updated by tompng (tomoya ishida) 10 months ago

Not same. https://bugs.ruby-lang.org/issues/20083 is related to regexp optimization from ruby 3.2.
This issue is not because it's same result in older ruby version 3.0 and 3.1

Actions

Also available in: Atom PDF

Like0
Like0Like0