import Foundation
let pattern = #"Remarks: ([^\r]+)Members:"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
GBRG0A 00005 JULIEx 11/27/17 11:03:12 X3311073-00X DAMAGE
Dig No : X3311073 Rev : 00X Digstart: 11/27/17 11:01
Rcvd : 11/27/17 11:03 Priority: 0 Expires : 12/24/17 23:59
Org Dig: X3311073 Rcvd: 11/27/17 11:01
Firm : KNOX CONSTRUCTION Caller: DUSTIN KNOX
CoAddr1: 1386 BRIDGEPORT RD
City,St: MAQUON, IL Zip : 61458
Phone : 309-337-6576 Ext :
Call Bk: Done For : PATTY BAILEY
SiteCnt: DUSTIN KNOX Phone : 309-337-6576
County : KNOX Place: GALESBURG CIT
Address: 522 ISLE ROYALE RD
Subdiv : Cross: LOSEY ST
Grids : T11NR01E09SW
BestFit: 40.954957/-90.400618 40.954938/-90.399043
: 40.953819/-90.400632 40.953799/-90.399057
PreMark: YES Directional Boring: NO Depth>7Ft: NO
Locatn : IN THE CITY OF GALESBURG,
WrkType: FENCE POST INSTALLATION ***HIT LINE****
Extent : LOCATE: THE WEST SIDE OF THE HOUSE.
Remarks: REFER TO DIG# X003241591 TO ALL COMPANIES, CALLER STATES HIT A
: MISMARKED CENTURY LINK LINE. CREW IS ON SITE. CALLED IN BY DUSTIN.
Members: COMC0A GBRG0A GSD0A GSD0B IPC6A SCNT3A USIC0A
View map at:
http://newtin.julie1call.com/newtinweb/map_tkt.nap?TRG=32WSVUQRTTVORRtwo2
"""##
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