regex and ios5 stringByMatching ==> NSRegularExpression

家住魔仙堡 提交于 2020-01-01 05:53:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!