ric*_*son 7 regex ios nsregularexpression
我需要一些帮助来构建一个正则表达式来从长字符串中删除带有搜索项的href链接,然后我将其解析为Web视图
href字符串的示例: <a href="/search/?search=Huntington">Huntington</a>
我想删除everthing但链接的纯文本(只是链接本身),但有麻烦
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<a href=\"/search/?search=([A-Z][a-z])\"" options:NSRegularExpressionCaseInsensitive error:&error];
Run Code Online (Sandbox Code Playgroud)
任何帮助都会受到极大的欢迎
谢谢
我认为
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<a href=\"[^\"]+\">([^<]+)</a>" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"$1"];
Run Code Online (Sandbox Code Playgroud)
应该工作(我测试了TextMate中的正则表达式,但没有在XCode中测试).
| 归档时间: |
|
| 查看次数: |
2701 次 |
| 最近记录: |