Skip to content

Instantly share code, notes, and snippets.

@blasten
Created January 6, 2015 19:52
Show Gist options
  • Save blasten/e82a50c857f1854b2d17 to your computer and use it in GitHub Desktop.
Save blasten/e82a50c857f1854b2d17 to your computer and use it in GitHub Desktop.
Infix operator for regular expressions.
// Declare `~>` operator
infix operator ~> {}
// Define the `~>` operator
//
// Example:
// if inputStr ~> "^[a-zA-Z]*$" {
// println("\(inputStr) only has letters")
// }
public func ~> (input: String, pattern: String) -> Bool {
return (input as NSString).rangeOfString(pattern, options: .RegularExpressionSearch).location != NSNotFound
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment