How to remove comment HTML element in a String in iOS

390 views Asked by At

This is the last part of my String:

</div>

</noscript><!-- A g3.js-t oldalanként egyszer, a </body> zárótag előtt kell meghívni -->

<script type="text/javascript" charset="utf-8" src="//ad.adverticum.net/g3.js"></script>





        <div id="autosuggest"><ul></ul></div>

    </body>

</html>

And this is how I want to remove the comment element, but it does not work:

var regex = NSRegularExpression(pattern: "<!--[^<]*-->", options: NSRegularExpressionOptions.CaseInsensitive, error: nil)!
str = regex.stringByReplacingMatchesInString(str, options: nil, range: NSMakeRange(0, count(str)), withTemplate: "")

Any idea why?

1

There are 1 answers

0
Artal On BEST ANSWER

You can try using a slightly different regex:

var regex = NSRegularExpression(pattern: "<!--[\\s\\S]*-->", options: NSRegularExpressionOptions.CaseInsensitive, error: nil)!