import Foundation
let pattern = #"id\=\"(?<id>[a-zA-Z][^_]+(\.*))"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
10-10-2019 14:04:25.863 +0200 WARN DispatchSjaak - Queued job id="c1111__c63422sss23344__search__search12339_157e345.73734_AF27BCF9-C4E0-4D04-B4E3-3r", seadex=application_wab_p
id="w34_aW0uY3Jpc2lz_aW0uY3Jpc2lz__search__search36_15703344710104.14022286_FB3D64CC-984D-4FAB-B724-5D14BA490FE3AppID == "ANDROID", "MB Android App", search_id="1570701613.3403_5F230059-1DF0-4750-B165-087Der444425949E17" - QUEUED reason="The maximum nu
= "HELL", "MB", search_id="xxx1570701613.3403_5F230059-1DF0-4750-B165-087Der444425933244349E17" - QUEUED reason="The maximum nu
"""#
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