[swift-evolution] Draft: Regular Expression in Swift

Dave DeLong delong at apple.com
Thu Aug 10 13:30:32 CDT 2017


> On Aug 10, 2017, at 11:48 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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.

This goes back to the idea of “non-standard libraries” that ship with Swift, but aren’t imported by default. I think a “Swift.Regex” module would be awesome, but I agree that it probably doesn’t need to be in the standard library.

Dave

> 
> 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.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list