2

我有一个小问题,我正在使用一个代码片段从 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:@""];

感谢帮助!

4

1 回答 1

0

尝试这个:

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

}

于 2012-08-14T08:15:07.617 回答