Closed jasonbobier closed 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
Also note that "36,769" works correctly.
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
@hamishknight Should I be putting Regex bugs straight into swift-experimental-string-processing
? I wasn't sure since it was listed as experimental still.
@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) :)
let p = "^[1-9][0-9]?[0-9]?(?:,?[0-9]{3})*$"
works correctly
@jasonbobier Any workaround for this? Actually we are trying this from Ionic Cordova with XCode @natecook1000 when can we expect this release?
@mdivya-symplr My work around was to use [0-9]?[0-9]?
instead of [0-9]{0,2}
.
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