Project

General

Profile

Actions

Bug #22429

open

regex empty capture group in a counted loop prevents a match

Bug #22429: regex empty capture group in a counted loop prevents a match

Added by robertmorelli (Robert Morelli) about 1 month ago. Updated 3 days ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [arm64-darwin27]
[ruby-core:127080]

Description

repro:

/\A(?:(){1,2}?a)+\z/.match?("aa")     # false
/\A(?:(?:){1,2}?a)+\z/.match?("aa")   # true
/\A(?:(){1,2}a)+\z/.match?("aa")      # true

An empty capture () behaves differently from (?:). Perl, Python and Oniguruma 6.9.10 return true for all three.

Updated by matz (Yukihiro Matsumoto) 3 days ago Actions #1 [ruby-core:127605]

I agree this is a bug. An empty capture group should not change whether the pattern matches, and all three patterns should return true. Please fix it.

Matz.

Actions

Also available in: PDF Atom