         }
     }
     
-    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

    }

    // instance methods
    func startOfLine(enabled: Bool = true) -> Self {
        prefixes = enabled ? "^" : ""

        return self
    }

    func endOfLine(enabled: Bool = true) -> Self {
        suffixes = enabled ? "$" : ""

        return self
    }

    func then(string: String) -> Self {
        return add("(?:\(sanitize(string)))")
    }

    // alias for then
    func find(string: String) -> Self {
        return then(string)
    }

    func maybe(string: String) -> Self {
        return add("(?:\(sanitize(string)))?")
    }
    
    func anything() -> Self {
        return add("(?:.*)")
    }
    
    func anythingBut(string: String) -> Self {
        return add("(?:[^\(sanitize(string))]*)")
    }

    func something() -> Self {
        return add("(?:.+)")
    }

    func somethingBut(string: String) -> Self {
        return add("(?:[^\(sanitize(string))]+)")
    }

    func lineBreak() -> Self {
        return add("(?:(?:\n)|(?:\r\n))")
    }

    // alias for lineBreak
    func br() -> Self {
        return lineBreak()
    }

    func tab() -> Self {
        return add("\t")
    }

    func word() -> Self {
        return add("\\w+")
    }
    
    func anyOf(string: String) -> Self {
        return add("(?:[\(sanitize(string))])")
    }
    
    // alias for anyOf
    func any(string: String) -> Self {
        return anyOf(string)
    }

    func withAnyCase(enabled: Bool = true) -> Self {
        if enabled {
            return addModifier("i")
        }

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

}

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


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

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

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