iOS RangeOfString NSRegularExpressionSearch

时间:2012-06-14 12:39:08

标签: regex nsrange

我有一个小问题,我使用一个代码段从iOS字符串中删除html代码:

while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
        s = [s stringByReplacingCharactersInRange:r withString:@""];

现在我需要移除一些块,比如。为什么此代码段不起作用:

while ((r = [s rangeOfString:@"<style[^>]+style>" options:NSRegularExpressionSearch]).location != NSNotFound)
    s = [s stringByReplacingCharactersInRange:r withString:@""];

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个:

while ((r = [s rangeOfString:@"<style[^>]+>[^>]+</style>" options:NSRegularExpressionSearch]).location != NSNotFound) {
   s = [s stringByReplacingCharactersInRange:r withString:@""];

}