【发布时间】:2012-06-17 11:50:40
【问题描述】:
我有一个小问题,我正在使用一个代码 sn-p 从 iOS 字符串中删除 html 代码:
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r withString:@""];
现在我需要删除一些块,例如 .为什么这个 sn-p 不起作用:
while ((r = [s rangeOfString:@"<style[^>]+style>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r withString:@""];
感谢您的帮助!
【问题讨论】:
-
阅读:stackoverflow.com/tags/regex/info 除非您对输入做出更多假设,否则最好使用解析器来完成这项工作。