import Foundation
let pattern = #"(?![\U00002619\U00002661\U00002665\U00002763\U00002764\U00002765\U00002766\U00002767\U00002E96\U00002E97\U00002F3C\U0001F394\U0001F48C\U0001F48F\U0001F491\U0001F493\U0001F494\U0001F495\U0001F496\U0001F497\U0001F498\U0001F499\U0001F49A\U0001F49B\U0001F49C\U0001F49D\U0001F49E\U0001F49F\U0001F4D6\U0001F5A4\U0001F60D\U0001F618\U0001F63B\U0001F970\U0001F9E1])[\U00002600-\U000027BF\U0001f300-\U0001f64F\U0001f680-\U0001f6FF]"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #""#
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