Created
June 24, 2021 12:30
-
-
Save jamestapping/72b369db6db17d26ceaf3111c5d1d173 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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