Skip to content

Instantly share code, notes, and snippets.

@oNguyenVanThieu
Created May 15, 2017 12:04
Show Gist options
  • Select an option

  • Save oNguyenVanThieu/56823415aea7f60561448b2b2c37fdac to your computer and use it in GitHub Desktop.

Select an option

Save oNguyenVanThieu/56823415aea7f60561448b2b2c37fdac to your computer and use it in GitHub Desktop.
Regex in Swift 3 for iOS
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