import Foundation
let pattern = #"([\w]+,[\w]+\s+[\w]\s+[\d]{1,2}[\S\s\.]+[\d]{4})"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
TC TOURISTIK GMBH HOTEL LIST (L/6X) AS OF : 25.07.2016
L/CENPA ARRIVAL-LIST COPY : 001
ARRIVAL:08.08.2016 14 DAYS BEFORE ARRIVAL PAGE : 1173/ 9
ADDRESS : L/CENPA CODE : 1FCH7
CENTER PARCS CENTER PARCS LE LAC D'AILETTE
PB1342/ACCOUNTS RECEIVABLE BTB
B NL-3000 ROTTERDAM 1FCH CHAMPAGNE/RHE
--------------------------------------------------------------------------------
POS NO TRAVELLER SEX BOARD
I STATE I I AGE I BOOKING-DATE
I I I I I DURATION I I
I I I I I I ARRIVAL/DEPARTURE
V V V V V V V V V
--------------------------------------------------------------------------------
ABBREVIATIONS FOR BOARD: OV=WITHOUT CATERING, UF=BREAKFAST, HP=HALF-BOARD,
VP=FULL-BOARD, AI=ALL INCLUSIVE, LP=CATERING AS DESCRIBED
--------------------------------------------------------------------------------
1FCH7 G CP LE LAC D'AILETTE MDWK / SSR-DESK BELGIUM
THOMAS COOK BE BUNGALOWS
6 H ***BUNGALOWS WITH 4 ROOMS***
BATH, SHOWER, WC, LA387 PREMIUM
13501629 FRENCH/UNITS: 01
1 ORGERIT,BENOIT M 00 4 08.08-12.08 OV 19.07.2016
2 MACK,KRISTYNA F 00 4 08.08-12.08 OV 19.07.2016
3 ORGERIT,LILOU C 09 4 08.08-12.08 OV 19.07.2016
4 ORGERIT,TOM C 07 4 08.08-12.08 OV 19.07.2016
5 ORGERIT,YANIS C 03 4 08.08-12.08 OV 19.07.2016
6 COLSON,LOUKA C 07 4 08.08-12.08 OV 19.07.2016
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
if let firstMatch = regex.firstMatch(in: testString, range: stringRange) {
let result: [String] = (1 ..< firstMatch.numberOfRanges).map { (testString as NSString).substring(with: firstMatch.range(at: $0)) }
print(result)
} else {
print("No matches were found.")
}
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