             let templateArray = Array<UInt8>(template.utf8)
             replacedStringArray.replaceRange(start ..<  end, with: templateArray)
 
-            guard var replacedString = String(data: replacedStringArray) else {
+            guard let _replacedString = String(data: replacedStringArray) else {
                 break
             }
+
+            var replacedString = _replacedString
 
             let templateDelta = template.utf8.count - (end - start)
             let templateDeltaIndex = replacedString.utf8.startIndex.advancedBy(Int(end + templateDelta))

// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import Gamut

struct RegexError : ErrorType {
    let description: String

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

        return groups
    }

    public func replace(string: String, withTemplate template: String, options: MatchOptions = []) -> String {
        var string = string
        let maxMatches = 10
        var totalReplacedString: String = ""

