import Foundation
let pattern = #"("UID\s*([^\n\r]*))"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
{
"Tabelle1": [
{
"Nr.": "1",
"Firma": "Alba Reisen/Versicherungen/Darlehen H. Kajtazi",
"Rechtsform": "EIU",
"Sitz": "Rapperswil-Jona",
"Kanton": "SG",
"UID": "CHE‑101.868.757"
},
{
"Nr.": "2",
"Firma": "Alybaba - Schischa Laden, Aly",
"Rechtsform": "EIU",
"Sitz": "Wil (SG)",
"Kanton": "SG",
"UID": "CHE‑102.012.121"
},
{
"Nr.": "3",
"Firma": "Bluamawerkstatt zur Linde Marianne Bislin-Lieberherr",
"Rechtsform": "EIU",
"Sitz": "Pfäfers",
"Kanton": "SG",
"UID": "CHE‑217.602.289"
},
]
}
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1,"X":"""#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression