2

i have a small problem, i am using one code snippet to remove html code from iOS string:

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

and now i need to remove some blocks, like . Why this snippet is not working:

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

Thanks for help!

ekussberg
  • 559
  • 1
  • 8
  • 19
  • Read this: http://stackoverflow.com/tags/regex/info Unless you give more assumptions about the input, it is better to use parser to do the job. – nhahtdh Jun 14 '12 at 12:47

1 Answers1

0

Try this:

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

}

Akirayjin
  • 657
  • 1
  • 7
  • 11