Created
January 6, 2015 19:52
-
-
Save blasten/e82a50c857f1854b2d17 to your computer and use it in GitHub Desktop.
Infix operator for regular expressions.
This file contains 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
// 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