Search code examples
swiftregexxcrun

Using new Swift regex from xcrun


Why am I not seeing the new Swift regex stuff when I call Swift via xcrun? Example:

~/Desktop/test.swift:

let x = /1/ // totally legal in an iOS or macOS project

At the command line:

% xcrun swift ~/Desktop/test.swift
/Users/mattm1/Desktop/test.swift:1:9: error: '/' is not a prefix unary operator
let x = /1/
        ^
/Users/mattm1/Desktop/test.swift:1:11: error: '/' is not a postfix unary operator
let x = /1/

What's gone wrong? My Swift language version seems high enough:

% xcrun swift --version
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.1 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0

Solution

  • The Xcode 14.3 release notes state that the new regex syntax requires passing -enable-upcoming-feature BareSlashRegexLiterals to the compiler to enable the feature: https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes