import Foundation
let pattern = #"Xpra(?<vcxXPRA>\s\d{1,2}\/\d{1,2}\/\d{1,2})\sF:(?<vcxXPRAfreqname>\w{1,9})\s(?<vcxXPRAfreq>\d{3},\d{3})\sTx\((?<vcxXPRAtxPTT>\d\d\d\d)\s(?<vcxXPRAtxPTTmin>\d{2,4}):(?<vcxXPRAtxPTTsec>\d{2,4})\)\sRx\((?<vcxXPRArxSQ>\d\d\d\d)\s(?<vcxXPRArxSQmin>\d{2,4}):(?<vcxXPRArxSQsec>\d{2,4})\);$"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
VCX_Stat;31.07.2018 20:43:59;S;ATCC#3 V 3 0 VCX - SVS ACC Phone/vieint1044(1):366001->371701 Voc TRM:nrm.cl.clr T:0:19 CL: 42 PL: 42 CI: 0 CPT:4;
VCX_Stat;14.10.2018 23:40:13;S;INN#3 V 3 0 'inn2pat_1003' (4) Total: 0:29;
VCX_Stat;14.10.2018 23:39:57;S;ATCC#1 V 1 0 Xpra 8/1/1 F:MIL3 139,100 Tx(0000 00:00) Rx(0001 00:04);
VCX_Stat;14.10.2018 23:38:47;S;ATCC#2 V 2 0 VIE BRA/bravie0501:362999->999999 Voc REJ:unall.num. T:0:00 CL: 44 PL: 44 CI: 0 CPT:4;
VCX_Stat;14.10.2018 23:38:35;S;ATCC#1 V 1 0 VCX - SVS ACCFuKOR_/vieint1049(2):676135->661635 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:35;S;ATCC#1 V 1 0 INN - VIE__2MBit__/innvie1201(3):676135->661635 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:35;S;INN#3 V 3 0 INN2 - VOR_________/inn2vor_1005(2):676135->661635 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:35;S;INN#3 V 3 0 INN - VIE__2MBit__/innvie1201(3):676135->661635 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:23;S;INN#3 V 3 0 INN - VIE__2MBit__/innvie1201(3):676134->661634 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:23;S;ATCC#1 V 1 0 /Qsig2M 4/1/2(28):676134->661634 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:23;S;ATCC#3 V 3 0 /Qsig2M 4/1/1(28):676134->661634 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
VCX_Stat;14.10.2018 23:38:23;S;ATCC#1 V 1 0 INN - VIE__2MBit__/innvie1201(3):676134->661634 Voc TRM:nrm.cl.clr T:0:09 CL: 8 PL: 8 CI: 0 CPT:3;
"""##
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