import Foundation
let pattern = #"(?<=the date is ).*?(?=\s*the place is)|(?<=the place is ).*?(?=\s*the people are)|(?<=the people are ).*"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"<a href=\"http://vnexpress.net/tin-tuc/the-gioi/putin-noi-se-tiep-tuc-hop-tac-voi-phuong-tay-3236453.html\"><img width=130 height=100 src=\"http://s.f29.img.vnecdn.net/2015/06/19/pu2-2249-1434719288_180x108.jpg\" ></a></br>Tổng thống Nga Vladimir Putin tự tin rằng hợp tác của Moscow với Phương Tây sẽ vẫn tiếp tục, bất chấp việc Liên minh châu Âu (EU) công bố sẽ kéo dài các lệnh trừng phạt thêm 6 tháng."#
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