Skip to content

"\r?" regex doesn't seem to work properly #718

New issue

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

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

Already on GitHub? # to your account

Open
MarsupialFan opened this issue Feb 8, 2024 · 1 comment
Open

"\r?" regex doesn't seem to work properly #718

MarsupialFan opened this issue Feb 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MarsupialFan
Copy link

Description

Regex("\r?\n") and other variants don't match "\r\n":

    print(try #/\r?\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"

See more "not matching" variants, and some related "matching" ones, in the reproduction section below.

Reproduction

        print(try #/\r?\n/#.firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try #/\r?\n/#.firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try #/(\r)?\n/#.firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try #/\r{0,1}\n/#.firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try #/(\r){0,1}\n/#.firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try #/\r?\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"
        print(try #/(\r)?\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"
        print(try #/\r{0,1}\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"
        print(try #/(\r){0,1}\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"
        print(try #/\r\n/#.firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try Regex("\r?\n").firstMatch(in: "\n") == nil ? "not matched" : "matched")  // prints "matched"
        print(try Regex("\r?\n").firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "not matched"
        print(try Regex("\r\n").firstMatch(in: "\r\n") == nil ? "not matched" : "matched")  // prints "matched"

Expected behavior

I expect all the "not matched" lines above to print "matched"

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Additional information

Xcode 15.2 (15C500b)
macOS Sonoma 14.2.1
Mac mini M2 2023

@MarsupialFan MarsupialFan added the bug Something isn't working label Feb 8, 2024
@AnthonyLatsis
Copy link

@hamishknight Does this need a transfer?

@hamishknight hamishknight transferred this issue from swiftlang/swift Feb 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants