 import Foundation
 
 public struct Regex {
-    public typealias Match = (String, Range<String.Index>)
     
     private var regexPattern: NSRegularExpression
     

}

extension String {
    public func match(regex: Regex) -> [Regex.Match] {
        return regex.matchWithPattern(self)
    }
    

        return regexPattern.pattern
    }
    
    internal func matchWithPattern(str: String) -> Match {
        let results = regexPattern.matchesInString(str, options: .ReportCompletion, range: NSRange(location: 0, length: str.startIndex.distanceTo(str.endIndex)))
        var components = [(String, Range<String.Index>)]()
        results.lazy.forEach {
            let stringRange = str.startIndex.advancedBy($0.range.location)..<str.startIndex.advancedBy($0.range.location + $0.range.length)
            components.append(str.substringWithRange(stringRange), stringRange)
        }
        return Match(components: components)
    }
    
    internal func replaceMatchesInString(str: String, replacement: String) -> String {
