4 ms·
Swift introduces RegexBuilder to make regex easier, but I think it is a bit too verbose: https://developer.apple.com/documentation/regexbuilder?changes=_2_2 htt
by gardaani 4y ago
Swift introduces RegexBuilder to make regex easier, but I think it is a bit too verbose: https://developer.apple.com/documentation/regexbuilder?changes=_2_2 https://developer.apple.com/documentation/regexbuilder?chang...
- Someone 4y agoFor simple regexes, Swift has short literals, and (AFAIK) you can mix and match the DSL and the short literals. https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md https://github.com/apple/swift-evolution/blob/main/proposals... gives this example: // A regex for extracting a currency (dollars or pounds) and amount from input // with precisely the form /[$£]\d+\.\d{2}/ let regex = Regex { Capture { /[$£]/ } TryCapture { /\d+/ "." /\d{2}/ } transform: { Amount(twoDecimalPlaces: $0) } } That gives you control over the verbosity. Aside: all of this is nice, but does anybody know whether compilation speed (which can be notoriously bad) improved in the latest Swift beta?