import Foundation
let pattern = #"<[\s\S]+?>"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
covid sucks and I want to go outside <!--/* Font Definitions */@font-face{font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;}@font-
face{font-family:""Cambria Math"";panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face{font-family:Calibri;panose-
1:2 15 5 2 2 2 4 3 2 4;}@font-face{font-family:""Bradley Hand ITC"";panose-1:3 7 4 2 5 3 2 3 2 3;}/*
Style Definitions */p.MsoNormal, li.MsoNormal, div.MsoNormal{margin:0in;margin-bottom:.0001pt;font-
size:11.0pt;font-family:""Calibri"",sans-serif;}p.MsoListParagraph, li.MsoListParagraph,
div.MsoListParagraph{m{margin-bottom:0in;}--> pop goes the peanut.
this is text before the junk starts <!--/* Font Definitions */@font-face{font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;}@font-
face{font-family:""Camb
NEW LINE!
NEW LINE!
ria Math"";panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face{font-family:Calibri;panose-
1:2 15 5 2 2 2 4 3 2 4;}@font-face{font-family:""Bradley Hand ITC"";panose-1:3 7 4 2 5 3 2 3 2 3;}/*
Style Definitions */p.MsoNormal, li.MsoNormal, div.MsoNormal{margin:0in;margin-bottom:.0001pt;font-
size:11.0pt;font-family:""Calibri"",sans-serif;}p.MsoListParagraph, li.MsoListParagraph,
div.MsoListParagraph{m{margin-bottom:0in;}--> ...and this is the bit afterwards even if the junk has line returns.
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #""#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression