ExSwift icon indicating copy to clipboard operation
ExSwift copied to clipboard

Regex support

Open michaeleisel opened this issue 10 years ago • 2 comments

I was thinking, since Google doesn't turn up any authoritative Regex Swift libraries, Regex would be a good idea. I haven't heard of any way to write out a Regex pattern without it being escaped, but oh well. I was thinking of adding a prefix operator, "/", that takes a String, so you would define a Regex literal like this:

let a: Regex = /"[0-9]*"

I would also add the =~ operator, a subscript lookup on strings, and almost all of Ruby's stuff for regexes, which you can find by searching for "regexp" on this page: http://www.ruby-doc.org/core-2.2.0/String.html

One question is whether or not to use iOS's existing regular expression class, NSRegularExpression. I don't know a lot about it, but it seems to reasonable to just make extension methods for it as needed, and perhaps subclass it as we need in the future.

Thoughts?

michaeleisel avatar Feb 02 '15 21:02 michaeleisel

Since there's a lot of stuff that we can do with regexps, we should consider starting a new library/framework, something like a Swift version of RegExKit meets ruby (and maybe more).

And yes, using NSRegularExpression it's the most reasonable option in order to offer a consistent interface to the iOS/OS X frameworks.

pNre avatar Feb 03 '15 09:02 pNre

I'll be traveling for a while so I don't want to maintain a library like that, but this summer I might be around to help.

michaeleisel avatar Feb 03 '15 16:02 michaeleisel