From: "tompng (tomoya ishida) via ruby-core" Date: 2023-12-27T10:56:47+00:00 Subject: [ruby-core:115931] [Ruby master Bug#20097] Regexp#match? with empty capture group repeat is inconsistent Issue #20097 has been reported by tompng (tomoya ishida). ---------------------------------------- Bug #20097: Regexp#match? with empty capture group repeat is inconsistent https://bugs.ruby-lang.org/issues/20097 * Author: tompng (tomoya ishida) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +MN [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- It sometimes matches and sometimes does not, depend on repeat quantifier number. ~~~ruby # 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. ~~~ruby 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 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/