import Foundation
let pattern = #"(?i),([^,]*),([^,]*),"ViewerURL""#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
2015-10-07T08:59:28,42eba5da-2637-4df0-ad31-2b868a74fced,FMD4080N0W,HKGRANMC-06,xxx.xxx.com,lxxxxxx229,n/a,wfshell shell,ICA Seamless Host Agent,2c693e3b-087b-4ad5-9664-8647feb39989,,Windows,https://xxxxxx:4884/xxxxxx/SlideViewer.aspx?SessionID=42EBA5DA-2637-4DF0-AD31-2B868A74FCED&DisplayOnAir=false&lang=en&SSID=2C693E3B-087B-4AD5-9664-8647FEB39989
"FirstScreenshotTime","SessionId","ClientName","ServerName","DomainName","LoginName","UserName","ApplicationName","WindowTitle","ScreenshotID","Command","OS","ViewerURL"
"""#
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