import Foundation
let pattern = #"(?=_{20,}|From:|On\s\w{3},\s\w{3}\s\d{1,2},\s\d{4}\sat\s\d{1,2}:\d{2})"#
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let testString = #"""
Great thank you
________________________________
From: Blake <blake@foursocial.uk>
Sent: Saturday, August 31, 2024 9:46:12 AM
To: blake hoang <bjh2004@hotmail.co.uk>
Subject: Re: Ignition. Campaign
Thanks , yes we can do it
---
Blake Junior
Managing Director | Foursocial.
blake@foursocial.uk<mailto:blake@foursocial.uk>
Submission Links<https://linktr.ee/foursocial1>
[https://ci3.googleusercontent.com/mail-sig/AIorK4yeSFbHM5imdVzOjDTr7LwNvS9gqpyQ83uajylr7mDBuRn5ymG1jlev6Zz8vvgQMzDLAYjFLcR7LVLu]
On Sat, Aug 31, 2024 at 9:45 AM blake hoang <bjh2004@hotmail.co.uk<mailto:bjh2004@hotmail.co.uk>> wrote:
Hey there let me know the fee
"""#
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