Skip to content

Regex compare not case-insensitive for single optional characters #852

@jdberry

Description

@jdberry

Description

When a case-insensitive regex contains an optional character, the optional character is not compared in a case-insensitive fashion. For instance, the regex /ab?c/.ignoresCase() will match "AbC", but will fail to match "ABC".

Reproduction

let pattern = /ab?c/.ignoresCase()
let tests = ["abc", "Abc", "ABC", "ac", "AC", "AbC", "aBc"]

for test in tests {
    let matched = test.wholeMatch(of: pattern) != nil
    print("\(matched ? "pass" : "FAIL"): \(test)")
}

when that code is run in a playground, the following is output:

pass: abc
pass: Abc
FAIL: ABC
pass: ac
pass: AC
pass: AbC
FAIL: aBc

Expected behavior

I expect all of those tests to pass.

Environment

% swiftc --version
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

Note that the tests do all pass for this form: /a(b)?c/.ignoresCase()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions