From a6e221e5d45966eb74971f011c6c5314ca451bf0 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 10 Mar 2022 10:35:28 +0800 Subject: [PATCH] UPE // Regex patch in NSRange and option flags. --- UserPhraseEditor/StringExtension.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UserPhraseEditor/StringExtension.swift b/UserPhraseEditor/StringExtension.swift index 0db07ae6..230e58ab 100644 --- a/UserPhraseEditor/StringExtension.swift +++ b/UserPhraseEditor/StringExtension.swift @@ -22,8 +22,8 @@ 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: self.utf16.count) + let regex = try NSRegularExpression(pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines]) + let range = NSRange(self.startIndex..., in: self) self = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: replaceWith) } catch { return } }