[swift-evolution] Empower String type with regular expression
John Joyce
uchuugaka at me.com
Fri Jan 1 18:44:23 CST 2016
> > On Dec 8, 2015, at 12:14 PM, Jerome Paschoud via swift-evolution <swift-evolution at swift.org <https://lists.swift.org/mailman/listinfo/swift-evolution>> wrote:
> >
> > I would like to see the String type to support regular expression per default. I think that a language that advertise itself as being a good scripting language should provide in its default implementation an easy way (=~ for example in Perl) to use regular expressions. I know that one can use the NSRegularExpression, but who really what to first create an NSRegularExpression object(whit all the nice escaping operation that come with every \), then get a NSTextCheckingResult, then get a range (and what I mean is a NSRange and not a NSRange<String.Index>) and finally perform slicing of your original string.
>
> Just MHO, but I’d really really like to see proper regex support in Swift someday.
>
> I think it could fit naturally into the pattern matching syntax we already have - the obvious syntax for this pattern would use // delimiters.
>
> It is also probably worth burning first-class language support for regexes. This would allow specifying variable captures inline in the pattern, would allow flexible syntax for defining regexes, support powerful extensions to the base regex model (e.g. Perl 6 style), and would provide better compile-time checking and error recovery for mistakes.
>
> -Chris
I know this is an old thread already, but this sure would be one of the major breakout pieces of functionality.
If Swift had native regular expressions, without all the noise you see in the Objective-C API that exposes ICU regular expressions, the adoption rate would be huge.
If they were *truly* native, as in somebody sat down and built an NFA (or one of the fancier approaches that mixes with DFA) state machine, Swift's best-in-class Unicode support would and could result in amazing things.
It'd boost the scripting use of Swift tremendously and seal the deal as a server side language.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160102/78bd39f0/attachment.html>
More information about the swift-evolution
mailing list