views:

357

answers:

2

Hi all, Is there a guide to using regular expressions in objective c? Specifically what to type into the "Reg. Ex." field in a core data property?

In particular, how to limit input to a set amount of numbers/letters only, and for UK Post Codes?

Thanks!

+5  A: 

According to the Apple documentation, the NSPredicate regex support implements the ICU package, so check their pages for documentation:

ICU Regex Documentation

For example, a regular expression of [0-9a-zA-Z]{5} could be used match on exactly 5 numbers or letters. (So would the shorter form of [\w\d]{5} though that also permits a few other characters)

Wade Williams
+1 correct, except that `\w` is an alphasymnumeric character class. In other words, `\w\d` is redundant, and just `\w` will suffice.
Dave DeLong
Thanks, the documentation is great!
Michael
+2  A: 

RegexKit Lite is a wrapper for the ICU regex library which adds a couple of methods to NSString that makes working with ICU a lot easier.

It also includes a short reference for the ICU regex syntax. For tutorials and a more complete reference I recommend regular-expressions.info, which is really handy whenever I write regular expressions.

Adrian
+1 whenever i have a regex question, www.regular-expressions.info almost always has the answer.
Dave DeLong