         }
     }
     
-    func beginCapture() -> Self {
+    public func beginCapture() -> Self {
         suffixes += ")"
         
         return add("(")
     }
     
-    func endCapture() -> Self {
-        suffixes = suffixes.substringToIndex(countElements(suffixes) - 1)
+    public func endCapture() -> Self {
+        suffixes = suffixes[suffixes.startIndex..<suffixes.endIndex.predecessor()]
         
         return add(")")
     }
     
-    func replace(string: String, template: String) -> String {
-        let range = NSRange(location: 0, length: countElements(string))
+    public func replace(string: String, template: String) -> String {
+        let range = NSRange(location: 0, length: count(string))
         
         return regularExpression.stringByReplacingMatchesInString(string, options: nil, range: range, withTemplate: template)
     }
     
-    func replace(string: String, with: String) -> String {
-        let range = NSRange(location: 0, length: countElements(string))
+    public func replace(string: String, with: String) -> String {
+        let range = NSRange(location: 0, length: count(string))
         let template = NSRegularExpression.escapedTemplateForString(with)
         
         return regularExpression.stringByReplacingMatchesInString(string, options: nil, range: range, withTemplate: template)
     }
     
-    func test(string: String) -> Bool {
-        let range = NSRange(location: 0, length: countElements(string))
+    public func test(string: String) -> Bool {
+        let range = NSRange(location: 0, length: count(string))
         
         if let result = regularExpression.firstMatchInString(string, options: nil, range: range) {
             return result.range.location != NSNotFound

    func option(forModifier modifier: Character) -> NSRegularExpressionOptions? {
        switch modifier {
        case "d": // UREGEX_UNIX_LINES
            return NSRegularExpressionOptions.UseUnixLineSeparators
        case "i": // UREGEX_CASE_INSENSITIVE
            return NSRegularExpressionOptions.CaseInsensitive
        case "x": // UREGEX_COMMENTS
            return NSRegularExpressionOptions.AllowCommentsAndWhitespace
        case "m": // UREGEX_MULTILINE
            return NSRegularExpressionOptions.AnchorsMatchLines
        case "s": // UREGEX_DOTALL
            return NSRegularExpressionOptions.DotMatchesLineSeparators
        case "u": // UREGEX_UWORD
            return NSRegularExpressionOptions.UseUnicodeWordBoundaries
        case "U": // UREGEX_LITERAL
            return NSRegularExpressionOptions.IgnoreMetacharacters
        default:
            fatalError("Unknown modifier")
            return nil
        }
    }

}

extension VerbalExpressions: Printable {
    var description: String { return pattern }
}


// Match operators
// Adapted from https://gist.github.com/JimRoepcke/d68dd41ee2fedc6a0c67
operator infix =~  { associativity left precedence 140 }
operator infix !=~ { associativity left precedence 140 }

func =~(lhs: String, rhs: VerbalExpressions) -> Bool {
    return rhs.test(lhs)
}

func !=~(lhs: String, rhs: VerbalExpressions) -> Bool {
    return !(lhs =~ rhs)
}

        
        let regex = NSRegularExpression(pattern: pattern, options: options, error: &error)
        
        if (error != nil) {
            return nil
        }
        
