import Foundation
let pattern = #"http.*zippyshare.*\.html"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
/b/ - Catalog https://55chan.org/b/catalog.html
Punch! Fansubs https://punchsubs.net/projeto/504/2
Zippyshare.com - PUNCH_Mushishi_-_06_SD.mkv https://www36.zippyshare.com/v/fBA0yWY3/file.html
Zippyshare.com - PUNCH_Mushishi_-_05_SD.mkv https://www26.zippyshare.com/v/9mWT8v7X/file.html
Zippyshare.com - PUNCH_Mushishi_-_04_SD.mkv https://www94.zippyshare.com/v/zLFWM4dC/file.html
Zippyshare.com - PUNCH_Mushishi_-_03_SD.mkv https://www18.zippyshare.com/v/7p1LRySL/file.html
Zippyshare.com - PUNCH_Mushishi_-_02_SD_REV3.mkv https://www95.zippyshare.com/v/nkMUaqNJ/file.html
Zippyshare.com - PUNCH_Mushishi_-_01_SD_REV3.mkv https://www31.zippyshare.com/v/2EkNKEwD/file.html
Cópia de OneClickRun.ipynb - Colaboratory https://colab.research.google.com/drive/1cSKxX5c2R4SLsdcndRoBzXgmZ2Fkd-sR?authuser=3#scrollTo=Mfg4A3KRjESb
Resultados da pesquisa por “Mushishi” – OldAge Subs https://oldagesubs.com/?s=Mushishi&submit=Pesquisar
"""##
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