import Foundation
let pattern = #"src: \"[^\>]*\"\}"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
<![CDATA[
var playerInstance = new artiplayer('artimedia-player-0404-1',{
source: {type: "video/mp4", src: "https://www.lolka.co.il/wp-content/uploads/2018/12/Screen-Shot-2018.jpg"},
poster: "https://www.lolka.co.il/wp-content/uploads/2018/12/Screen-Shot-2018-12-28-at-15.46.29-e1546004840977.png",
autoplay: false,
sitekey: '0404',
category: "test src: "varffff1"
});
]]>
[1]: <![CDATA[
var playerInstance = new artiplayer('artimedia-player-0404-3',{
source: {type: "video/mp4", src: "https://www.0404.co.il/wp-content/uploads/2019/01/WhatsApp-Video-2019-01-07-at-08.33.38.mp4"},
poster: "https://www.0404.co.il/wp-content/uploads/2019/01/WhatsApp-Image-2019-01-07-at-08.38.27.jpeg",
autoplay: false,
sitekey: '0404',
category: "test"
});
]]>
"""#
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