Skip to content

Instantly share code, notes, and snippets.

@jamestapping
Created June 24, 2021 12:30
Show Gist options
  • Save jamestapping/72b369db6db17d26ceaf3111c5d1d173 to your computer and use it in GitHub Desktop.
Save jamestapping/72b369db6db17d26ceaf3111c5d1d173 to your computer and use it in GitHub Desktop.
import Foundation
extension String {
mutating func removingRegexMatches(pattern: String, replaceWith: String = "") {
do {
let regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let range = NSRange(location: 0, length: count)
self = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith)
} catch { return }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment