import Foundation
let pattern = #"""
Hash:
0xcba5ee76d1b322114c4e5b1a3e00edf1065bf0346bef88ee603a8a061908db88https://img.shields.io/azure-devops/coverage/0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3/https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684/974618121112?color=https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112&label=%3Cimg%20alt%3D%22Azure%20DevOps%20coverage%22%20src%3D%22https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112%22%3E&logo=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&logoColor=https%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684&style=plastic
"""#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"https://img.shields.io/azure-devops/coverage/0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3/https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684/974618121112?color=https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112&label=%3Cimg%20alt%3D%22Azure%20DevOps%20coverage%22%20src%3D%22https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112%22%3E&logo=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&logoColor=https%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684&style=plastic.. image:: https://img.shields.io/azure-devops/coverage/0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3/https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684/974618121112?color=https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112&label=%3Cimg%20alt%3D%22Azure%20DevOps%20coverage%22%20src%3D%22https%3A%2F%2Fimg.shields.io%2Fazure-devops%2Fcoverage%2F0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3%2Fhttps%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684%2F974618121112%22%3E&logo=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&logoColor=https%3A%2F%2Ftokenview.com%2Fen%2Fsearch%2F0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684&style=plastic :alt: Azure DevOps coverage<img alt="Azure DevOps coverage" src="https://img.shields.io/azure-devops/coverage/0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3/https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684/974618121112">https://img.shields.io/azure-devops/coverage/0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3/https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f19684/974618121112https://tokenview.com/en/search/0xdf6ac64b05e8bb7ca5c8d31ff44a00544eb039a7f467a424ae1c1e1926f196840xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3"#
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