开发者

reg expression in objective c fails on new line

I want to remove all script tags 开发者_Python百科from HTML using objective c.

I wrote this reg ex:

html1 = [html1 stringByReplacingOccurrencesOfString:@"<script.+?</script>" withString:@"xxx" options: NSRegularExpressionCaseInsensitive|NSRegularExpressionSearch | NSRegularExpressionDotMatchesLineSeparators range:NSMakeRange (0, [html1 length])];

This work on strings with no new lines such as:

html1 = @"<script> blah blah </script>";

But fails on strings with new lines, such as:

html1 = @"<script> blah \n blah </script>";

Anyone know what I'm doing wrong?

Thanks!

ps I'm aware that this fails on nested script tags.


I don't believe those regular expression options (such as NSRegularExpressionDotMatchesLineSeparators) are valid for stringByReplacingOccurrencesOfString:withString:options: — AFAIK, NSRegularExpressionSearch just gives basic regex support. For more advanced regular expressions, you'll want to use the NSRegularExpression class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜