             var regexMatches = [regmatch_t](count: maxMatches, repeatedValue: regmatch_t())
             let result = regexec(&preg, string, regexMatches.count, &regexMatches, options.rawValue)
 
-            if result == REG_NOMATCH {
+            if result == 1 {
                 break
             }
 

        
        return totalReplacedString + string
    }
}

extension String {
    public init?(data: [UInt8]) {
        var string = ""
        var decoder = UTF8()
        var generator = data.generate()
        var finished = false

        while !finished {
            let decodingResult = decoder.decode(&generator)
            switch decodingResult {
            case .Result(let char): string.append(char)
            case .EmptyInput: finished = true
            case .Error: return nil
            }
        }

        self.init(string)
    }
}
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

struct RegexError: ErrorType {
    let description: String

    static func errorFromResult(result: Int32, preg: regex_t) -> RegexError {
        var preg = preg
        var buffer = [Int8](count: Int(BUFSIZ), repeatedValue: 0)
        regerror(result, &preg, &buffer, buffer.count)
        let description = String.fromCString(buffer)!
