import Foundation
let pattern = #"INVIMA [A-Z0-9-]+"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
<div class="productDescription">NEUROBION 100MG/150MG CAJA X 30 TABLETAS<br><br>Modo de Uso: Vía Oral<br>Componente Activo: Vitamina B1 (Tiamina) Y Vitamina B6 (Piridoxina)<br>INVIMA 2019M-0009578-R1</div>
<div class="productDescription">NEUROBION INYECTABLE X 3 AMPOLLAS<br><br>Modo de Uso: Vía Intramuscular<br>Componente Activo:Vitamina B1 (Tiamina) 100 Mg, Vitamina B6 (Piridoxina) 100 Mg Y Vitamina B12 (Cianocobalamina) 1 Mg. Solucion Inyectable Con Tecnología Doble Camara. <br>INVIMA 2015M-13939-R2<br><img class="" data-src="/arquivos/RX.png?v=636054173313030000" src="/arquivos/RX.png?v=636054173313030000"></div>
"""#
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