Skip to content

Posts tagged ‘codepad’

25
Jul

PCRE on the iPad

I’ve been working on an iPad application that relies heavily on preexisting regular expressions.   iPhone OS 3.2 doesn’t have much regular expression support, so naturally, I’ve been using RegexKitLite, a very easy to use Objective-C wrapper around the built-in ICU regex engine.  If you’ve never used it before I strongly recommend it.

Unfortunately, I found that I was having a lot of errors.   Turns out that ICU doesn’t support named capture groups, a feature many of these regular expressions required.   At first I thought, “Maybe I can go through them all and modify them so they didn’t need that feature,” but that would be far too tedious and inflexible for the future.  Then I thought, “Maybe I can add the feature to ICU, get it pushed into the release version then Apple will add it to the next update of the OS.”  Right.

I found that the best way to solve my problem would be to compile PCRE, the engine these expressions were originally written for (I think), for the iPad, which turned out to be very simple to do.  I also found ObjPCRE, an Objective-C wrapper that somebody had written a while back, but its interface seemed confusing and I never got it to work.  So I decided to figure out PCRE’s C API and write my own.  PCRE’s man pages are quite thorough and very helpful.  I only wish they had clear documentation of each function like Apple does.  Perhaps they’ve never heard of Doxygen.

Finally, I wrote PCRERegex, my Objective-C wrapper around PCRE.  It’s not very complete, I wrote it with a specific task in mind.  So don’t think you can just replace RegexKitLite with it just yet.  Maybe someday.  Maybe.

Go check it out on GitHub.