【发布时间】:2011-01-15 14:01:43
【问题描述】:
给定一个NSString *test = @"...href="/functions?q=KEYWORD\x26amp...";
如何使用 NSRegularExpression 从字符串中提取单词 KEYWORD?
我在 iOS SDK 4.2 上尝试了以下 NSRegularExpression,但它无法找到文本。下面的代码看起来好吗?
NSRegularExpression *testRegex = [NSRegularExpression regularExpressionWithPattern:@"(?<=href=\"\\/functions\\?q=).+?(?=\\x26amp])" options:0 error:nil];
NSRange result = [testRegex rangeOfFirstMatchInString:test options:0 range:NSMakeRange(0, [test length])];
【问题讨论】:
标签: iphone regex ios pattern-matching text-extraction