Skip to content

Instantly share code, notes, and snippets.

@matthijn
Created November 26, 2014 20:25
Show Gist options
  • Save matthijn/40d2402a75c976a160c7 to your computer and use it in GitHub Desktop.
Save matthijn/40d2402a75c976a160c7 to your computer and use it in GitHub Desktop.
Ruby like regular expression matching for Swift
// 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