     global = regex.global
     regex = new RegExp(regex.source, 'gm')
 
-    traverseRecursively = (text, startIndex, endIndex, lengthDelta) =>
+    text = @getText()
+    startIndex = @characterIndexForPosition(range.start)
+    endIndex = @characterIndexForPosition(range.end)
+    lengthDelta = 0
+
+    while true
       regex.lastIndex = startIndex
       return unless match = regex.exec(text)
 

      startPosition = @positionForCharacterIndex(matchStartIndex + lengthDelta)
      endPosition = @positionForCharacterIndex(matchEndIndex + lengthDelta)
      range = new Range(startPosition, endPosition)
      recurse = true
      replacementText = null
      stop = -> recurse = false
      replace = (text) -> replacementText = text
      iterator(match, range, { stop, replace })



    matches.reverse()

    keepLooping = true
    stop = -> keepLooping = false
    replacementText = null
    replace = (text) -> replacementText = text

