I believe I'm running Swift 5.7 from the command line on macOS Monterey, 12.4, and that Swift 5.7 implements the new Regex class and regex literal syntax, but It doesn't seem to. I need help resolving this so that I can use the 5.7 regex feature.
For the following file "parse.swift". Swift didn't seem to understand the Swift 5.7 regex literal: /.../ syntax; it generated errors it shouldn't for what was clearly legitimate regex pattern, so I tried a different approach and discovered it doesn't recognize the new Regex class itself.
let pattern = #"^ ,([A-Z][A-Z])([0-9][0-9]),(.*?),(.*?) "#
let regex = try! Regex(pattern)
$ swift parse.swift < somefile
parse.swift:3:18: error: cannot find 'Regex' in scope let regex = try! Regex(pattern) ^~~~~
Is there something I need to import or do differently?
This is the version it says I'm running:
$ swift --version
Apple Swift version 5.7-dev (LLVM eecf02df5133efe, Swift ad06e7d7251311a) Target: arm64-apple-macosx12.0
I selected the 5.7 version of Swift by exporting the following from ~/.zshrc
@yonihemi, speaking of "easier with Xcode beta", I have that (14.0 beta 4), but I still can't use regex on my macOS 12.4 machine. Is there no way around this? Doesn't the beta come with the necessary runtimes?
Specifically, I get "'Regex' is only available in macOS 13.0 or newer".
Edit: It does work for iOS playgrounds, for instance, but also not for macOS playgrounds.
If any Linux folks end up here the same is true for that toolchain. Using 5.7 doesn't have -enable-experimental-string-processing enabled by default. Passing that or updating to 5.7.2 (I didn't test 5.7.1) fixes it