Skip to content

Case-insensitive regex with repetitions does not match uppercase characters correctly #785

Closed
@fwcd

Description

@fwcd

Description

In case-insensitive regular expressions containing repetitions (+ or *), the repeated part is not matched correctly against differently cased characters in the string to be searched.

Reproduction

func test(_ pattern: Regex<Substring>, on s: String) throws {
    print("\(s) contains \(try pattern.firstMatch(in: s)?.output ?? "no match")")
}

for s in ["ab", "Ab"] {
    try test(#/ab/#.ignoresCase(), on: s)
    try test(#/a*b/#.ignoresCase(), on: s)
    try test(#/a+b/#.ignoresCase(), on: s)
}

This snippet outputs

ab contains ab
ab contains ab
ab contains ab
Ab contains Ab
Ab contains b
Ab contains no match

Expected behavior

I would expect it to output

ab contains ab
ab contains ab
ab contains ab
Ab contains Ab
Ab contains Ab
Ab contains Ab

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions