import Foundation
let pattern = #"[\x{0200}-\x{FFFF}]"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
[11:51] <Lucas807> ๐๐๐จ๐ผ;๐จ๐ด ๐ข๐๐ ๐ญษช๐ค๐ญ๐ ๐ด๐ฆ๐ ๐๐๐๐๐ส๐๐.๐๐ฃ
[11:51] <Lucas807> ๐๐๐ด๐ผ;๐๐ ๐๐ด๐ แด
๐๐ค๐กแด ๐๐ถ๐ฏ ๐แด๐๐ฐ๐จ๐ฏ๐บแด.๐ฃ๐
[11:49] <Damien537> ๐ด๐ธ๐ด๐;๐ด๐ ๐๐๐ฑ ๐น๐๐ฐ๐๐ธ s๐๐ฃ ๐๐๐ผ๐๐๐๐ฎ๐ถ.า๐ฃ
[11:49] <Damien537> ๐๐ฌ๐ด๐;๐จ๐ฐ ๐ฆ๐ฐ๐ ๐ก๐๐๐๐ ๐๐๐ฃ ๐ค๐ธ๐ธ๐ฌ๐๐ฃ๐ฎ๐.๐ฃ๐ฃ
[11:48] <Axel937> ๐ฌ๐๐๐;ษข๐ค ๐ฎ๐๐ ๐ฑ๐๐ค๐๐ ๐๐ถ๐ ๐๐ฌ๐ธ๐๐จ๐ณ๐ช๐ช.๐ฏ๐ฟ
[11:48] <Axel937> ๐ด๐ ๐๐;๐๐ด ๐ฎ๐ฐ๐ ๐ก๐๐๐นแด ๐ด๐ถ๐ ๐ผแด๐๐๐๐แด๐.าส
[11:46] <Leon231> ๐ด๐๐ธ๐;๐๐ ๐ฆ๐๐ฝ ๐๐๐ผ๐ญ๐ฐ ๐ฐ๐๐ฟ แด๐ฐ๐ ๐ผ๐ด๐๐ฎ๐.๐ป๐
[11:46] <Leon231> ๐๐ธ๐ฌ๐ธ;๐๐ฐ ๐พ๐ผ๐ ๐ก๐๐๐น๐ ๐ผ๐พ๐ณ ๐ธ๐๐ฐแด๐๐๐ฎ๐.๐๐ฟ
[11:44] <Maxime678> ๐ธ๐๐จ๐ ;๐๐ ๐ข๐๐ แด
๐ฒ๐ค๐๐ธ s๐๐ ๐ธ๐๐๐๐ด๐๐ถแด.๐๐
[11:44] <Maxime678> ๐จ๐๐๐ฐ;๐ค๐ด แด๐๐ ๐ฅ๐๐ผ๐๐ ๐๐๐ฏ ๐ ๐๐๐ธ๐ฐ๐ป๐แด.๐ฏ๐
[11:43] <Hugo645> ๐๐ ๐๐ฌ;๐๐ ๐s๐ฅ ๐ฝ๐๐๐๐ ๐๐๐ ๐แดแด๐๐ด๐๐๐ฎ.า๐
[11:43] <Hugo645> ๐จ๐ผ๐ธ๐ผ;๐๐จ ๐ข๐๐ฝ ๐ษช๐ฐแด๐ ๐๐ข๐ ๐๐ผ๐๐๐๐๐๐.๐๐
[11:41] <Tristan549> ๐แด๐๐;๐๐ฐ ๐๐ฐ๐ ๐๐๐๐
๐ผ ๐ฐ๐๐ป ๐ฐแด๐ธ๐๐๐๐๐บ.๐ฃ๐ฃ
[11:41] <Tristan549> ๐๐ผ๐๐;ษข๐ ๐๐ด๐ แด
๐๐ค๐๐ ๐ ๐พส ๐๐๐ธ๐ผ๐๐ป๐ช๐บ.๐๐
Test sans caractรจres bizarres
Et ๐ชv๐c
"""#
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