问题
How do I change this line with the equivalent NSRegularExpression
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];
Thank you
回答1:
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.
来源:https://stackoverflow.com/questions/8166179/regex-and-ios5-stringbymatching-nsregularexpression