import Foundation
let pattern = #">([^<>]*\S)<"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
<tr>
<td class="no-min-width " style="" width="45" data-col="0">
<a href="/[ステージオブマジック]島村卯月">
<img src="https://cdn.img-conv.gamerch.com/img.gamerch.com/imascg-slstage-wiki/wikidb_thumbnail/338316/individual_200.jpg?d=20190419162924&q=20" class="lazy ui_thumbnail" data-original="https://cdn.img-conv.gamerch.com/img.gamerch.com/imascg-slstage-wiki/wikidb_thumbnail/338316/individual_200.jpg?d=20190419162924&q=20" alt="[ステージオブマジック]島村卯月"> </a>
</td>
<td class=" " style="" data-col="1">
<a href="/[ステージオブマジック]島村卯月">
<span data-jscol_sort="[ステージオブマジック]島村卯月">[ステージオブマジック]島村卯月</span>
</a>
</td>
<td class=" " style="" data-col="2">
<span data-jscol_sort="島村卯月">
<a href="https://imascg-slstage-wiki.gamerch.com/%E5%B3%B6%E6%9D%91%E5%8D%AF%E6%9C%88" class="ui_page_match" title="島村卯月">
島村卯月
</a>
</span>
</td>
<td class=" " style="" data-col="3">
<span data-jscol_sort="キュート">キュート</span>
</td>
<td class=" " style="" data-col="4">
</td>
</tr>
"""#
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