import Foundation
let pattern = #"P\.A\.C\.\(\) inicial P\.A\.C\. \(\) Sopave da cota devida 3a\. parcela contemplação devidas devidas pago efetivados Saldo Sopave(.*?)\(\*\) Proposta de Admissão em Consórcio"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
e
&
Anexo VI
Rodobens Administração e Promoções Ltda.
Comissões sobre vendas de cotas de consórcio - Imóveis Data-base: 22 de maio de 2002
Em reais % de
% de comissão _ comissão Comissão Comissão Comissão Estorno de Total de Saldo Numero Crédito _ devida conforme planilha - Status inicial devida na devida na comissões comissões Valor __ Estornos planilha P.A.C.() inicial P.A.C. () Sopave da cota devida 3a. parcela contemplação devidas devidas pago efetivados Saldo Sopave 150.620 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 655,00 0,00 125,00 (300,00) 150.619 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 655,00 0,00 125,00 (300,00) 150.610 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 780,00 0,00 0,00 355,00 150.607 80.000,00 2,62% 1,42% Ativo 2.096,00 400,00 0,00 0,00 2.496,00 2.496,00 0,00 0,00 1.136,00 150.605 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 780,00 0,00 0,00 355,00 150.560 30.000,00 2,62% 1,42% Inativo 786,00 0,00 0,00 336,00 450,00 450,00 0,00 0,00 426,00 150.556 80.000,00 0,00% 1,42% Inativo 0,00 0,00 0,00 0,00 0,00 0,00 0,00 0,00 1.136,00 150.533 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 655,00 0,00 0,00 0,00 0.00 355,00 150.531 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 655,00 0,00 0,00 0,00 0,00 355,00 150.522 30.000,00 2,62% 1,42% Ativo 786,00 150,00 0,00 0,00 936,00 936,00 0,00 0,00 426,00 150.493 50.000,00 2,62% 1,42% Ativo 1.310,00 250,00 0,00 0,00 1.560,00 1.560,00 0,00 0,00 710,00 150.443 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 780,00 0,00 0,00 355,00 150.439 25.000,00 2,62% 1,42% Ativo 655,00 125,00 0,00 0,00 780,00 780,00 0,00 0,00 355,00 150.432 35.000,00 2,62% 1,42% Ativo 917,00 175,00 0,00 0,00 1.092,00 1.092,00 0.00 0,00 497,00 150.426 25.000,00 2,62% 3,12% Ativo 655,00 125,00 125,00 0,00 905,00 0,00 0,00 905,00 (125,00) 150.420 25.000,00 2,62% 2,62% Ativo 655,00 125,00 0,00 0,00 780,00 780,00 0,00 0,00 655,00 150.404 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280,00) (300,00) 150.403 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280.00) (300,00) 150.401 55.000,00 2,62% 1,42% Inativo 1.441,00 0,00 0,00 616,00 825,00 825,00 0,00 0,00 (660.00) 150.400 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280,00) (300.00) 150.397 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280,00) (200,00) 150.394 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280,06) (200,00) 150.392 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280,00) (300,00) 150.391 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280.00) (300,00) 150.388 25.000,00 2,62% 1,42% Inativo 655,00 0,00 0,00 280,00 375,00 655,00 0,00 (280.00) (300,00) (*) Proposta de Admissão em Consórcio (**) PAC constante no relatório de reposição de setembro de 2001 1?
"""#
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