import Foundation
let pattern = #"("")([^<>]*?)("")(?=(?:[^>]*?(?:<|$)))"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
"FRENCH","11.03.2022 13:36","DocumentType.APPROVAL_AV","Approbation de la personne responsable du marché (""RdM"")"
"SPANISH","11.03.2022 13:36","DocumentType.APPROVAL_AV","Aprobación del o de la responsable de la orden"
"ENGLISH","11.03.2022 13:36","DocumentType.ARGE_DECLARATION","Declaration of the consortium (""ARGE"")"
"FRENCH","11.03.2022 13:36","DocumentType.ARGE_DECLARATION","Déclaration du groupement"
"SPANISH","11.03.2022 13:36","DocumentType.ARGE_DECLARATION","Declaración del consorcio (en Alemania “ARGE”)"
"ENGLISH","11.03.2022 13:54","appHelpSignpostText","If you have any technical issues, please do not hesitate to contact us personally through the following channels:<br /><br /><a href=""https://test.com/"" target=""_blank"">{{downloadIcon}}Guide</a> to help you enter your request."
"FRENCH","11.03.2022 13:54","appHelpSignpostText","Si vous rencontrez des difficultés techniques, n’hésitez pas à nous contacter personnellement via les canaux suivants : <br /><br /><a href=""https://test.com/"" target=""_blank"">{{downloadIcon}}Guide</a>, pour vous aider à saisir votre demande."
"SPANISH","11.03.2022 13:54","appHelpSignpostText","Si tiene dificultades técnicas, no dude en ponerse personalmente en contacto con nosotros o nosotras a través de los siguientes canales:<br /><br /><a href=""https://test.com/"" target=""_blank"">{{downloadIcon}}Guía</a>, que le servirá de ayuda para introducir su solicitud."
"ENGLISH","11.03.2022 13:36","appraisalAndConsultingRadio","Consulting contracts for <b>Test Service (TeS)</b>"
"FRENCH","11.03.2022 13:36","appraisalAndConsultingRadio","Contrats de conseil pour <b>Test Service (TeS)</b>"
"ENGLISH","11.03.2022 13:36","argeRadio","Consortium (called ""Arge"" in German)"
"FRENCH","11.03.2022 13:36","argeRadio","Groupement momentané d’entreprises (groupement)"
"SPANISH","11.03.2022 13:36","appraisalAndConsultingRadio","Contratos de asesoramiento para <b>Test (Tst)</b>"
"ENGLISH","11.03.2022 13:54", "sustainabilitySignpostText","The goal of sustainable management is to ensure that our earth is worth living on for future generations.<br /><br />More about GIZ’s sustainability activities can be found in the IDA communities <a href=""https://test.com/"" target=""_blank"">{{purIcon}}Corporate Sustainability""</a> (more general) or <a href=""https://test.com/"" target=""_blank"">{{purIcon}}Sustainable Procurement</a> (especially for procurement). There you will find extensive information and handouts to help you make our planet a little more climate-friendly.<br /><br />And this begins not least in procurement."
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let matches = regex.matches(in: testString, range: stringRange)
var result: [[String]] = []
for match in matches {
var groups: [String] = []
for rangeIndex in 1 ..< match.numberOfRanges {
let nsRange = match.range(at: rangeIndex)
guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue }
let string = (testString as NSString).substring(with: nsRange)
groups.append(string)
}
if !groups.isEmpty {
result.append(groups)
}
}
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