Pattern match like a boss.
Create:
let greeting = Regex("hello (world|universe)")
let magic: Regex = "(.*)"
Match:
if greeting.matches("hello universe!") {
print("wow, you're friendly!")
}
Pattern match:
switch someTextFromTheInternet {
case Regex("DROP DATABASE (.+)"):
// TODO: patch security hole
default:
break
}
Capture:
let greeting: Regex = "hello (world|universe|swift)"
if let subject = greeting.match("hello swift")?.captures[0] {
print("ohai \(subject)")
}
Put this in your Cartfile:
github "sharplet/Regex"
Put this in your Podfile:
pod "Regex", git: "https://github.com/sharplet/Regex.git"