Created
May 15, 2017 12:04
-
-
Save oNguyenVanThieu/56823415aea7f60561448b2b2c37fdac to your computer and use it in GitHub Desktop.
Regex in Swift 3 for iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| func regex(input: String, rule: String) -> Bool { | |
| return NSPredicate(format:"SELF MATCHES %@", rule).evaluate(with: input) | |
| } | |
| let ruleString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
| let inputString = "A0z._%+-@Ab1.-.Ab" | |
| let regexBool = regex(input: inputString, rule: ruleString) | |
| print(regexBool) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment