I’m trying to remove everything from a string that is NOT an html tag or comment tag.
I have this code which works quite well for most strings:
NSString* HTMLPlainText = [HTML stringByReplacingOccurrencesOfString:@"<(.*?)>" withString:@" " options: NSRegularExpressionSearch range:NSMakeRange (0, [HTML length])];
But it does not work for strings that contain new lines. For example this string will not be altered: “< tag name \n more tag > words I want”
The new line throws it off. I can run a whole other search to remove all /n tags before running this one and that works, but it seems like there must be a better way….
Thanks!
Instead of using the
NSRegularExpressionSearchflag and using simpleNSStringmethods, create an actualNSRegularExpressionobject, and use it’s methods to do the replacement.That will give you much more flexibility, including configuration options for newlines.