11
有人可以幫助我與NSPredicate一起使用Regex嗎?NSPredicate和正則表達式
NSString *regex = @"(?:[A-Za-z0-9])";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if ([pred evaluateWithObject:mystring])
{
//do something
}
測試上面的wth mystring - qstring123似乎不工作。我期待它進入if條件,因爲它應該匹配正則表達式。
此外,我需要一個允許逗號和空格的alpha數字的正則表達式。
這項工作?
@"(?:[A-Za-z0-9])*(?:,[A-sa-z0-9)*(?:\s[A-sa-s0-9])"
請幫忙。
最後我錯過了+。我實際上使用*,它的工作。有什麼不同? – Dave 2010-03-16 23:53:57
'*'匹配0次或更多次,'+'匹配1次或更多次。 – 2010-03-16 23:54:27