diff --git a/VoiceInk/Services/AIEnhancementOutputFilter.swift b/VoiceInk/Services/AIEnhancementOutputFilter.swift
index f55c136..7118d2b 100644
--- a/VoiceInk/Services/AIEnhancementOutputFilter.swift
+++ b/VoiceInk/Services/AIEnhancementOutputFilter.swift
@@ -2,6 +2,7 @@ import Foundation
struct AIEnhancementOutputFilter {
static func filter(_ text: String) -> String {
+ var processedText = text
let patterns = [
#"(?s)(.*?)"#,
#"(?s)(.*?)"#,
@@ -10,18 +11,11 @@ struct AIEnhancementOutputFilter {
for pattern in patterns {
if let regex = try? NSRegularExpression(pattern: pattern) {
- let range = NSRange(text.startIndex..., in: text)
- if let match = regex.firstMatch(in: text, options: [], range: range) {
- // Extract content from the first capturing group
- if match.numberOfRanges > 1, let contentRange = Range(match.range(at: 1), in: text) {
- let extractedText = String(text[contentRange])
- return extractedText.trimmingCharacters(in: .whitespacesAndNewlines)
- }
- }
+ let range = NSRange(processedText.startIndex..., in: processedText)
+ processedText = regex.stringByReplacingMatches(in: processedText, options: [], range: range, withTemplate: "")
}
}
- // If no tags are found, return the original text as is.
- return text
+ return processedText.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
\ No newline at end of file