Question: I want to test user input to see if the entire input matches the following regex. How do I do that with Swift?

`[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]`

Answer: 
Look like you are trying to verify email addresses. Try this:

```
let test = "someone@somewhere.com"

do {
    let regex = try NSRegularExpression(pattern: "[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z]", options: [])
    if regex.firstMatchInString(test, options: [], range: NSMakeRange(0, test.utf16.count)) != nil {
        print("matched")
    } else {
        print("not matched")
    }
} catch let error as NSError {
    print(error.localizedDescription)
}

```

`NSRegularExpression` is still carrying a lot of the ObjC legacy behind it so it's pretty verbose to use.
I'm using this extension in all of my projects:

```
extension String {
    func matchsIn(regexString: String) -> Bool {
        do { let regex = try NSRegularExpression(pattern: regexString, options: [])
             return regex.firstMatch(in: self, options: [], range: NSMakeRange(0, self.utf8.count)) != nil
        } catch { return false }
    }
}

```