开发者

Regular expression for numbers

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜