Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jdberry opened this issue Dec 13, 2024 · 2 comments
Open

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

jdberry opened this issue Dec 13, 2024 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. transfer candidate The issue may belong in another repository

Comments

@jdberry
Copy link

jdberry commented Dec 13, 2024

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()

@jdberry jdberry added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Dec 13, 2024
@jdberry
Copy link
Author

jdberry commented Dec 13, 2024

I see that this is related to swiftlang/swift-experimental-string-processing#785. Is there an easy way to transfer this over, or should I re-create a ticket there?

@AnthonyLatsis
Copy link
Collaborator

Sure, we can transfer this for you.

cc @xedin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. transfer candidate The issue may belong in another repository
Projects
None yet
Development

No branches or pull requests

2 participants