         }
     }
     
+    /// Regex pattern used to match.
+    /// - Returns: `String` format of pattern
     public func toString() -> String {
         return regexPattern.pattern
     }
     
+    /**
+     Finds regex matches in a string.
+     - Parameter str: the `String` to find matches in
+     - Returns: A `Match` based on the matching result
+     */
     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>)]()


import Foundation

public struct Regex {
    
    private var regexPattern: NSRegularExpression

    return Regex(pattern: pattern)
}

infix operator =~ {}

public func =~ (input: String, regex: Regex) -> Bool {
    return regex.search(input) != nil
}

public func =~ (input: String, regexPatternStr: String) -> Bool {
    if let regex = Regex(pattern: regexPatternStr) {
        return regex.search(input) != nil
    }
    return false
}

extension String {
    /**
     Finds regex matches in the string. This method will find multiple matches in the string.
     - Parameter regex: `Regex` object that holds the pattern to find matches with
     - Returns: A `Match` based on the matching result
     */
    public func match(regex: Regex) -> Regex.Match {
        return regex.matchWithPattern(self)
    }
    
    /**
     Finds regex matches in the string and replaces those matches with the replacement string.
     - Parameter regex: `Regex` object that holds the pattern to find matches with
     - Parameter withString: The replacement `String` to insert in place of the match
     - Returns: A new `String` with the replacements applied
     */
    public func replace(regex: Regex, withString: String) -> String {
        return regex.replaceMatchesInString(self, replacement: withString)
    }
    
    /**
     Searches the string to find any match.
     - Parameter regex: `Regex` object that holds the pattern to find matches with
     - Returns: An optional `Int` of the location of the match
     */
    public func search(regex: Regex) -> Int? {
        return regex.search(self)
    }
