I have to check the third character in the string. I’m trying to do that with NSPredicate. I thought the regular expression should be ..3* so it will find every string with third character 3. But its not working and I did try some others approaches without success :(. Can someone help me ?
simple code to checking
- (IBAction)btnCheckPerformClick:(id)sender {
_chkOk.state = NO;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like[c] %@", _txtRegExpression.stringValue];
NSLog(@"%@", predicate);
if([predicate evaluateWithObject:_txtCheckingText.stringValue])
_chkOk.state = YES;
}
thanks
The
LIKEoperator in the predicate format language only understands simple wildcards (?and*). You need to useMATCHESif you want to use a regular expression.See the Predicate Programming Guide (String Comparisons) for more details.
Alternatively, use
NSRegularExpression.