Created
November 26, 2014 20:25
-
-
Save matthijn/40d2402a75c976a160c7 to your computer and use it in GitHub Desktop.
Ruby like regular expression matching for Swift
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
// Ruby like regular expression matching | |
infix operator =~ {} | |
func =~ (input: String, pattern: String) -> Bool | |
{ | |
return input.rangeOfString(pattern, options: .RegularExpressionSearch) != nil | |
} | |
// Example | |
if "foobaar" =~ "[a-z]*" | |
{ | |
println("Only letters") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment