import Foundation
let pattern = #"\s*<div class="new">.*?href="((?:.*?)channel=(.*?))".*?src="(.*?)".*?</a>\s*</div>"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .dotMatchesLineSeparators])
let testString = ##"""
<div class="new"> <a class="block" target="_blank" href="http://somesite:8080/hls/mango1.m3u8?token=34523sedfsdfsdf&e=123456789&channel=mango1" data-toggle="modal" data-target="#mango1">
<div class="image-container"> <img src="images/mango1.png" class="img-responsive" > </div>
</a> </div>
<div class="new"> <a class="block" target="_blank" href="http://somesite:8080/hls/mango2.m3u8?token=sfaesfraesgh452342&e=987654321&channel=mango2" data-toggle="modal" data-target="#mango2">
<div class="image-container"> <img src="images/mango2.png" class="img-responsive" > </div>
</a> </div>
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"HREF: \1\nCHANNEL: \2\nSRC: \3\n\n"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
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