swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

MarsupialFan opened this issue · comments

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

@hamishknight Does this need a transfer?