         }
         regExPattern += ")"
 
-        patternStr = patternStr.substring(from: patternStr.index(End.lowerBound, offsetBy: 2))
+        patternStr = patternStr.substring(from: patternStr.index(end, offsetBy: 2))
         continue
       }
 

      // RegEx matches.
      if patternStr.range(of: "{{")?.lowerBound == patternStr.startIndex {
        // This is the start of a regex match.  Scan for the }}.
        guard let End = patternStr.range(of: "}}") else {
          let loc = CheckLoc.inBuffer(pattern.baseAddress!, buf)
          diagnose(.error, loc, "found start of regex string with no end '}}'")
          return true

        offset = regVar.index(offset, offsetBy: 2)
      } else {
        switch firstChar {
        case brackets.open:
          bracketDepth += 1
        case brackets.close:
          if bracketDepth == 0 {
            diagnose(.error, .string(regVar), "missing closing \"\(brackets.close)\" for regex variable")
            return nil
          }
          bracketDepth -= 1
