You can use NSRegularExpression . It supports \b , btw, although you need to avoid it on the line:
NSString *regex = @"\\b-?1?[0-9]{2}(\\.[0-9]{1,2})?\\b";
Although, I think that \\W would be a better idea, since \\b prevent it from detecting a negative sign on the number.
Hope the best example:
NSString *string = <...your source string...>; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\W-?1?[0-9]{2}(\\.[0-9]{1,2})?\\W" options:0 error:&error]; NSRange range = [regex rangeOfFirstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; NSString *result = [string substringWithRange:range];
Hope this helps. :)
EDIT: fixed based on the comment below.
SynTruth Sep 12 '11 at 19:13 2011-09-12 19:13
source share