import Foundation
let pattern = #"https://internetinthecar-e2e\.((sfr|a1|swisscom|proximus|elisa|tango|telenor-no|telenor-se|yousee|plus|telia|bite-lv|bite-lt|a1-)\.)?iot\.vodafone\.com/sso/authorize/callback|https://internetinthecar-e2e-new\.iot\.vodafone\.com/sso/authorize/callback"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
(https://internetinthecar-e2e.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.sfr.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.a1.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.swisscom.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.proximus.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.elisa.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.tango.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.telenor-no.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.telenor-se.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.yousee.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.plus.iot.vodafone.com/sso/authorize/callback|https://internetinthecar-e2e.telia.iot.vodafone.com/sso/authorize/callback)
https://internetinthecar-e2e.bite-lv.iot.vodafone.com/sso/authorize/callback
internetinthecar-e2e.bite-lt.iot.vodafone.com
internetinthecar-e2e.a1-si.iot.vodafone.com
internetinthecar-e2e.cyta.iot.vodafone.com
internetinthecar-e2e.elisa-ee.iot.vodafone.com
internetinthecar-e2e.epic.iot.vodafone.com
internetinthecar-e2e.a1-hr.vodafone.com
internetinthecar-e2e.a1-bg.iot.vodafone.com
"""#
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