import Foundation
let pattern = #"Date:\n(.*)\n\nNumber"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive, .dotMatchesLineSeparators])
let testString = #"""
Voice Mail Message: Double click on the attachment to play the voice mail file.
Date:
12/01/2014 01:28:36 PM
Number:
800-123-4567, JOHN SMITH
CallerID:
123-456-7890, JANE DOE
Destination:
Voice Mail
File Duration:
00:00:37
======================
Name : Jane Doe
Address : 123 Fake Street , Miami , Florida
Phone : 123-456-7890
Ye, my name is Jane Doe. I own the property at 123 Fake Street , Miami , Florida. You sent me a couple of postcards. Let me know if you're interested in making an offer. it's a single family home.3 bedrooms, 2 baths. Has a single efficiency in the back, that's an additional rental income.
Again, Jane Doe and that's 123 Fake Street and my phone number is 123-456-7890. Thanks !
"""#
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