import Foundation
let pattern = #"<table class="clubs">(.*?)</table>"#
let regex = try! NSRegularExpression(pattern: pattern, options: .dotMatchesLineSeparators)
let testString = ##"""
<div class="box" style="padding:0px;">
<div class="box-heading" align="center" style="padding-top:2px; height:15px;">OUR CLUBS</div>
<div class="box-content" style="padding:0px 10px 0px 10x;margin:0px;">
<table class="clubs">
<tr>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Everton-tickets" rel="nofollow"><img src="image/data/everton.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#265da0;">Everton</span></a>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Manchester-United-Tickets" rel="nofollow"><img src="image/clubs/manchester-united.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#f20000;">Man United</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Chelsea" rel="nofollow"><img src="image/clubs/chelsea.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#003487;">Chelsea</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Arsenal" rel="nofollow"><img src="image/clubs/arsenal.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#d70127;">Arsenal</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Manchester-City" rel="nofollow"><img src="image/clubs/manchester-city.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#177389;">Man City</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Liverpool" rel="nofollow"><img src="image/clubs/liverpool.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#ba0109;">Liverpool</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/Tottenham-hotspur-tickets" rel="nofollow"><img src="image/data/tottenham.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#102654;">Tottenham</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/barcelona" rel="nofollow"><img src="image/data/barcela.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#a20045;">Barcelona</span></a></td>
<td width="11%" align="center" height="130"><a href="https://myticketsonline.eu/real-madrid" rel="nofollow"><img src="image/data/realmadrid.jpg" border="0" width="57"><br><br>
<span class="candara_bold" style="font-size:15px;color:#17377f;">Real Madrid</span></a></td></tr>
</table>
</div>
</div>
"""##
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