NSPredicate and Regex
Posted
by Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2010-03-16T23:18:42Z
Indexed on
2010/03/16
23:21 UTC
Read the original article
Hit count: 545
Can someone please help me with using Regex with NSPredicate?
NSString *regex = @"(?:[A-Za-z0-9])";
NSPredicate *pred = [NSPRedicate predicateWithFormat:@"SELF MATCHES %@", regex];
if ([pred evaluateWithObject:mystring])
{
//do something
}
testing the above wth mystring - qstring123 doesn't seem to work. I am expecting it to enter the if condition because it supposedly should match the regex.
Besides, I need a regex for alpha numberic allowing commas and spaces.
will this work?
@"(?:[A-Za-z0-9])*(?:,[A-sa-z0-9)*(?:\s[A-sa-s0-9])"
Please help.
© Stack Overflow or respective owner