UPE // Fix Surrogate-Pair Compatibility Issue with RegEx Function.
This commit is contained in:
parent
a82deb75a1
commit
1ad5efbb4c
|
@ -20,9 +20,10 @@ import Foundation
|
|||
|
||||
extension String {
|
||||
mutating func regReplace(pattern: String, replaceWith: String = "") {
|
||||
// Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914
|
||||
do {
|
||||
let regex = try NSRegularExpression(pattern: pattern, options: .caseInsensitive)
|
||||
let range = NSRange(location: 0, length: count)
|
||||
let range = NSRange(location: 0, length: self.utf16.count)
|
||||
self = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith)
|
||||
} catch { return }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue