itgiawa
itgiawa

Reputation: 1616

reg expression in objective c fails on new line

I want to remove all script tags 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.

Upvotes: 1

Views: 375

Answers (1)

Chuck
Chuck

Reputation: 237100

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.

Upvotes: 1

Related Questions