Skip to content

Instantly share code, notes, and snippets.

@claymcleod
Created February 21, 2015 02:06
Show Gist options
  • Save claymcleod/39214f470d71363d6410 to your computer and use it in GitHub Desktop.
Save claymcleod/39214f470d71363d6410 to your computer and use it in GitHub Desktop.
// Title: Regular Expressions with Swift
// Authors: Clay McLeod
// Description: A brief overview of regular expressions with Swift
// Section: Swift
// Subsection: General
import Foundation
var error: NSError?
let pattern = "[A-Za-z]atch"
let testingString = "Hatch"
let expression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error)
if let match = expression?.matchesInString(testingString, options: nil, range: NSMakeRange(0, countElements(testingString))) {
println("Testing string matched the regular expression!");
} else {
println("Match not found.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment