I need a regular expression to detect 开发者_StackOverflowat least one number in a string. Other characters can be anything. Please help me to implement this in objective C.
Regards,
Dilshan
\d+
Match one or more digit.
This is a very similar question to:
Regular Expressions in Objective-C and Core Data
Check ICU Regex Documentation for figuring out your regular expression needs
To match a digit anywhere in string use .*\\d.*. To implement in objective-c use NSPredicate try something like this:
NSString *matchphrase = @".*\\d.*";
BOOL match = NO;
NSString *item = @"string with d1g1it";
NSPredicate *matchPred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", matchphrase];
match = [matchPred evaluateWithObject:item];
More here
Edited according Dislhan comment.
加载中,请稍侯......
精彩评论