Skip to content

group quantified {0} reports an empty capture instead of nil #902

Open

Description

@robertmorelli

issue:

A group quantified {0} never runs but reports an empty capture. Every other spelling of a group that doesn't participate reports nil.

repro:

print("b".firstMatch(of: #/(a){0}b/#)!.1 as Any)      // Optional("")
print("b".firstMatch(of: #/(a){0,0}b/#)!.1 as Any)    // Optional("")
print("b".firstMatch(of: #/(a){0,1}b/#)!.1 as Any)    // nil
print("b".firstMatch(of: #/(a)?b/#)!.1 as Any)        // nil
print("b".firstMatch(of: #/(a)*b/#)!.1 as Any)        // nil
print("cb".firstMatch(of: #/(?:(a)|c)b/#)!.1 as Any)  // nil

expected:

nil for all six

actual:

Optional("") for {0} and {0,0}.

system:

Swift 6.4, macOS 27.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions