Announcing NSRegexTester

With the principle development work for Tiberius complete, I’m moving onto a new iOS project. I’m not sure how long it will take to develop, but it feels like a larger, more ambitious project, and I’m not even sure yet that I have the ability to do it. This is, therefore, the best kind of project.

One of this project’s components involves a great deal of parsing using regular expressions. I’m working on a UIView subclass that performs syntax highlighting, and writing the correct regular expressions to match the patterns in my target text has proven to be a challenge.

Regular expressions are a difficult skill to learn. But what they don’t tell you is that every language has its own subtly different implementation; techniques that work in Ruby, for example, don’t work in iOS. That’s because Ruby’s implementation is based on Oniguruma, whereas Apple is using the ICU project.

These implementation differences turn out to matter a great deal. As I’ve come to rely on Ruby’s delightful Rubular regex testing tool, I’ve also found that the results I get from it don’t apply to pattern matching in iOS. Sometimes.

So it seemed there was only one solution: build a Rubular that uses the very library I’m looking to target. I give you NSRegexTester.


It works pretty simply: put some text into the box on the left. Enter a regex string at the top and click Test. The left-hand text will appear on the right, with any matches highlighted. Rinse and repeat till you’re happy with your regex, and you can drop that into your code, knowing it’ll “just work”.

The application was built in about 30 minutes, but it took a few more hours to mess around with layout and adding the options window. The list of checkboxes presented a particular challenge; for some reason I can’t figure out how to make them behave as a collection, despite putting them into an NSMatrix. Arggh.

But maybe you can help, because I’m making the source code freely available on Github. Fork it and play around. There’s also a binary available from there if you just want the app.

It’s strange to me that I haven’t given away any of my code before. My Github profile is just a list of projects that I’ve forked for myself. Well, as 2013 arrives, I’m hoping to make a little change by giving something back. I hope there will be other developers like me, who will find this useful.