How do you replace more than two occurrence of \r
&\n
into one in a String?
if the sample string is
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit magna et quam maximus elementum et id ex.\r\n Donec luctus massa ut sapien consectetur blandit. Maecenas vehicula ex odio, eu sollicitudin felis vehicula sed. \nPhasellus hendrerit neque volutpat urna fermentum, eget cursus erat finibus. \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
should not remove single or two occurrences.
Tried this code:
let regex = try! NSRegularExpression(pattern: "[\r\n]+", options: NSRegularExpression.Options.caseInsensitive)
let range = NSMakeRange(0, sampleString.count)
let modString = regex.stringByReplacingMatches(in: sampleString, options: [], range: range, withTemplate: "")