Regular Expressions in Swift
Use regular expressions to pattern-match and extract data from strings in Swift.
Use regular expressions to pattern-match and extract data from strings in Swift.
import Foundation
let input = "My email is example@email.com"
let pattern = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
if let range = input.range(of: pattern, options: .regularExpression) {
let email = input[range]
print("Found email: \(email)")
}