swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.
Apache License 2.0
278 stars 47 forks source link

Regex fails to match correctly in Xcode 14.3 (iOS, macOS) and Xcode 14.2 (macOS) #640

Closed jasonbobier closed 1 year ago

jasonbobier commented 1 year ago

Please run the included playground in both Xcode 14.3 and Xcode 14.2. The regex should match the given string (and does in other regex engines). It will correctly match if you set the playground to iOS and run in 14.2. If the playground is set to macOS or it is run in Xcode 14.3, it will fail to match.

Regex.playground.zip

jasonbobier commented 1 year ago
let r = try Regex("[1-9][0-9]{0,2}(?:,?[0-9]{3})*")
let m = "36769".wholeMatch(of: r)

print(m?.0 ?? "no match")

This is the code

jasonbobier commented 1 year ago

Also note that "36,769" works correctly.

jasonbobier commented 1 year ago

And NSRegularExpression works correctly.

let s = "36769"
let p = "^[1-9][0-9]{0,2}(?:,?[0-9]{3})*$"

let r = try Regex(p)
let m = s.wholeMatch(of: r)

print(m?.0 ?? "no match")

let nsr = try NSRegularExpression(pattern: p)
let nsrm = nsr.firstMatch(in: s, range: NSRange(s.startIndex..., in: s))

if let nsrm {
    print(s[Range(nsrm.range, in: s)!])
} else {
    print("no match")
}

// prints:
//
// no match
// 36769
jasonbobier commented 1 year ago

@hamishknight Should I be putting Regex bugs straight into swift-experimental-string-processing? I wasn't sure since it was listed as experimental still.

hamishknight commented 1 year ago

@jasonbobier Yes, this is where the regex implementation lives. The repo really needs to be renamed (https://github.com/apple/swift-experimental-string-processing/issues/622) :)

jasonbobier commented 1 year ago

let p = "^[1-9][0-9]?[0-9]?(?:,?[0-9]{3})*$"

works correctly

mdivya-symplr commented 1 year ago

@jasonbobier Any workaround for this? Actually we are trying this from Ionic Cordova with XCode @natecook1000 when can we expect this release?

jasonbobier commented 1 year ago

@mdivya-symplr My work around was to use [0-9]?[0-9]? instead of [0-9]{0,2}.