What is the best method for using Regular Expressions within Objective-C?
There seems to be some open source project that provide regex support, can any one recommend one?
Also I looked at NSPredicate
, can anyone suggest any regex examples?
Background: I want use regex mainly for validation, IP's, email addresses, internal ID's etc
NSPredicate *predicate;
predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*@.*\..*'"];
BOOL result = [predicate evaluateWithObject:@"[email protected]"];
According to the Predicate guide:
Matches
The left hand expression equals the right hand expression using a regex-style comparison according to ICU v3 (for more details see the ICU User Guide for Regular Expressions).
There's even an example written by Apple that can be found in the guide.
Instead of SELF
you could also use a key path. (And possibly some other literals too.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With