import Foundation
let pattern = #"<li style="display: list-item;" class="mc-container"><a href="([^"]+)".*?data-querystring="id=(\d+)".*?<img src="([^"]+)".*?<a[^>]+>([^<]+)</a>"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"<li style="display: list-item;" class="mc-container"><a href="http://youpeliculasweb.com/cantinflas-2014" title="Cantinflas 2014 (2014) PelÃcula Online"><div class="tool mc-item"><div class="info_movie tile" data-tipped="http://youpeliculasweb.com/cantinflas-2014/info" data-querystring="id=4303"><div class="play_go"></div><img src="http://img-youpeliculas.com/images/2014/09/09/Cantinflas2B20142Bonline.jpg" alt="Cantinflas 2014 (2014) PelÃcula Online"></div></div></a><div class="library-show"><h4><div class="title-overflow"></div><a class="title" href="http://youpeliculasweb.com/cantinflas-2014" title="Cantinflas 2014 (2014) PelÃcula Online">Cantinflas 2014</a></h4></div></li>"#
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