import Foundation
let pattern = #"(?<=From:)((?:(?!>).)*)>"#
let regex = try! NSRegularExpression(pattern: pattern, options: .dotMatchesLineSeparators)
let testString = #"""
From: FirstName LastName <FirstName.MiddleName.LastName@someemail.com>
In-Reply-To: <fc7b93ca4dab.531f4e68@my.bcit.ca>
-------------------------------------------------
From: "FirstName. MiddleName =?iso-8859-1?b?TWFydO1uZXo=?= LastName"
<somemeail@something.otherthing.es>
Subject: Re: Some Randome Data
In-Reply-To: <42043F8EC804DB48A3C4AF477195328F272CB9@exchange.something.local>
-------------------------------------------------
From: "FirstName MiddleName LastName" <LastName@someemail.com>
Subject: Some Randome Subject
-------------------------------------------------
From: "FirstName. MiddleName =?iso-8859-1?b?TWFydO1uZXo=?= LastName"
<somemeail@something.otherthing.es
>
Subject: Re: Some Randome Data
In-Reply-To: <42043F8EC804DB48A3C4AF477195328F272CB9@exchange.something.local>
-------------------------------------------------
From: "FirstName. MiddleName =?iso-8859-1?b?TWFydO1uZXo=?= LastName"
<
somemeail@something.otherthing.es
>
Subject: Re: Some Randome Data
In-Reply-To: <42043F8EC804DB48A3C4AF477195328F272CB9@exchange.something.local>
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #""#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
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