DataCompiler // Regex patch in NSRange and option flags.
This commit is contained in:
parent
a6e221e5d4
commit
009a511d06
|
@ -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 }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue