#!/usr/bin/env swift; import Foundation import Utils // Begin Main let s:String = "Four score and seven years ago..." print("Match 1: " + String(s.match(NSRegularExpression(##"s.*e"##)))) print("Match 2: " + String(s.match(NSRegularExpression(##"\bs.*e\b"##)))) print("Match 3: " + String(s.match(NSRegularExpression(##"s...e"##)))) print("Match 4: " + String(s.match(NSRegularExpression(##"b.d"##)))) var subgroups:[String] = s.findFirst(NSRegularExpression(##"(\w+)\s*(\w+)"##)) print("Find First (with subgroups): " + Utils.listToString(subgroups)) subgroups = s.findFirst(NSRegularExpression(##"bad match"##)) print("Find First (bad match): " + Utils.listToString(subgroups)) var matches:[String] = s.findAll(NSRegularExpression(##"\w+"##)) print("Find All: (matches only)" + Utils.listToString(matches)) matches = s.findAll(NSRegularExpression(##"bad match"##)) print("Find All (bad match): " + Utils.listToString(matches)) exit(EXIT_SUCCESS)