diff --git a/matching.go b/matching.go index 56c6135..83f0000 100644 --- a/matching.go +++ b/matching.go @@ -169,6 +169,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset // i++ // } // Get the maximum index-range from the list + end := 0 if len(tempIndices) > 0 { indexToAdd := Reduce(tempIndices, func(i1 matchIndex, i2 matchIndex) matchIndex { r1 := i1.endIdx - i1.startIdx @@ -180,9 +181,14 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset }) if !overlaps(indexToAdd, indices) { indices, _ = unique_append(indices, indexToAdd) + end = indexToAdd.endIdx } } - return findAllMatchesHelper(start, str, indices, startIdx) + if end == 0 || end == startIdx-1 { // Since we incremented startIdx earlier, we need to check against the old startIdx + return findAllMatchesHelper(start, str, indices, startIdx) + } else { + return findAllMatchesHelper(start, str, indices, end) + } } currentStates = make([]*State, len(tempStates)) copy(currentStates, tempStates)