Regular Expressions in Swift

Yes, it would, but it begins to move towards composition which is in most cases the better solution.

You further define unary repetition operators like *, + and ? for strings as well as connection operators like | and concat which simply encode the operation into the string.

Anyway, I find normal functions to be better as there are limitations with regexes.

+1 for this idea. Not so much to add here.

Today it is pretty easy to make error in regex. Of course, we can write tests. But every developer have to repeat this work. Instead, compiler can be improved and check or validate regex literals.

1 Like

I came here from starting a seperate pitch before finding this thread. My main motivation was needing to use NSRegularExpression which is very Non-swifty. So much so, even when you set the docs to swift, some of the example code is Objective-C.

My RegEx learning came by way of perl and I think @Chris_Lattner3 has a good point about looking at and stealing some ideas from how Perl6/Raku handle regexes. Having a RegEx type I think would be great as we could type check at compile time if the regex literal itself compiles.

As for readability we could allow for composition like @tem suggests.

All I know is, I'd like to be rid of NSRegularExpression as something I need to care even the slightest about. I'm kinda new here - where do we go from here - a pitch? Some attempts at partial implementations?