DataCompiler // Regex patch in NSRange and option flags.

This commit is contained in:
ShikiSuen 2022-03-10 10:35:35 +08:00
parent 375d0a24c9
commit 50a09faba1
1 changed files with 2 additions and 2 deletions

View File

@ -23,8 +23,8 @@ fileprivate extension String {
mutating func regReplace(pattern: String, replaceWith: String = "") { mutating func regReplace(pattern: String, replaceWith: String = "") {
// Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914 // Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914
do { do {
let regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive) let regex = try NSRegularExpression(pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines])
let range = NSRange(location: 0, length: self.utf16.count) let range = NSRange(self.startIndex..., in: self)
self = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith) self = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith)
} catch { return } } catch { return }
} }