RegEx on iOS?

I’m currently in the process of converting an old project (written circa 2002) for use on iOS. (sounds fun, no?) However, there are a number of classes that make use of the RegEx class from the classic framework. I don’t suppose anyone knows of an equivalent that would allow regular expression search/replace for an iOS project? Any help much appreciated! (RegEx makes me nervous…)

I know it sounds bizarre, but you might be able to use SQLite to search your text as a data field.

http://stackoverflow.com/questions/5071601/how-do-i-use-regex-in-a-sqlite-query

You can implement the OS-native regex support with declares. I don’t think this has been built into iOSKit, but it might make a good addition.

https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSRegularExpression_Class/index.html#//apple_ref/doc/uid/TP40009708

Thanks for the replies!

Kem, I was hoping to avoid the use of Declares as I’m quite green with xojo, but I think your suggestion is the one to go with. Plus, what better way to learn… (Though I may come to regret that sentiment!)

David, that does look like a pretty cool solution, but it made my head hurt!

If I manage to get something working nicely with declares I’ll throw up a project later. Thanks again!

[quote=204828:@Kem Tekinay]You can implement the OS-native regex support with declares. I don’t think this has been built into iOSKit, but it might make a good addition.

https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSRegularExpression_Class/index.html#//apple_ref/doc/uid/TP40009708[/quote]
I’ll see what I can put together. I’ll need someone to test it of course because my knowledge of regex is very close to 0.

If you are using MacOSLib as a template, I already introduced the class there. Happy to test it for you too.

Just an update. The classes are written and Kem is helping to test them. We will post them once we make sure they work as expected.

The pull request is out there now. The only issue I’m having is getting it to raise an exception with a bad pattern, so that test currently fails. It’s a minor issue, though, so I don’t think it should hold up anything.

The classes have been added into iOSKit.

https://github.com/kingj5/iOSKit

xojo forum contributors make me happy! :slight_smile:

Many thanks Jason and Kem!