Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex and ios5 stringByMatching ==> NSRegularExpression

Tags:

regex

ios5

How do I change this line with the equivalent NSRegularExpression

NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];

Thank you

like image 484
JHT Avatar asked Dec 16 '22 07:12

JHT


1 Answers

Remember that you need iOS 4.0 or greater to use this:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"points:\\\"([^\\\"]*)\\\"" options:0 error:NULL];
NSTextCheckingResult *match = [regex firstMatchInString:apiResponse options:0 range:NSMakeRange(0, [apiResponse length])];
NSString *encodedPoints = [apiResponse substringWithRange:[match rangeAtIndex:1]];

Hope it helps.

like image 97
Adriano Santangeli Avatar answered Jan 12 '23 03:01

Adriano Santangeli