[swift-evolution] Draft: Regular Expression in Swift

Tino Heth 2th at gmx.de
Thu Aug 10 12:48:34 CDT 2017


I guess everyone agrees that there should be support for regular expressions - I'm just not sure where, how and when to integrate it…
People seem to have a (sometimes unhealthy…) passion for regex, so I'd like to encourage a critical look on their importance.
For example, I don't think they belong into the stdlib — there are more basic (and much more simple) things like a Result-type or an operator for function concatenation which are not included, so why should we treat regular expressions differently?
But It doesn't look like we'll see a fitting library that's bundled with Swift anytime soon, and third-party regex Frameworks imho would cause big confusion.

Anyways, as you suggest a special syntax, it would be required to integrate support into Swift itself… although this is even deeper than the stdlib, I'm more positive towards that direction, as it would allow some neat tricks:
The expressions could not only be checked, but also translated at compile time — which could give Swift a real kickstart to beat established solutions in terms of execution speed.
It would, on the other hand, not work for non-literal strings, so regular expressions that are created at runtime would still need extra support…

If Core would consider to include compile-time regular expressions in the future, I'd support adding the new syntax, even if it's only used like NSExpression in the first implementation. Without that option, I think it's not worth it, and I'd rather try to use custom operators to build matchers that don't follow any regex standard, but are fast and safe to use.


More information about the swift-evolution mailing list