import Foundation
let pattern = #"(conf\_ant|PV00476|PV00011|PV00501|PV00511|PV00521|PV00496|PV00016|PV00491|PV00516|PV00015|PV00018|PV00506|PV00486|PV00014|PV00481|PV00013|PV00502|PV00494|PV00485|PV00495|PV00019|PV00505|PV00500|PV00504|PV00020|PV00012|PV00479|PV00477|PV00522|PV00520|PV00514|PV00499|PV00510|PV00507|PV00492|PV00475|PV00487|PV00017|PV00512)\.html"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #""#
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