diff --git a/regex/matching.go b/regex/matching.go index 3dba3f0..e1e7d9b 100644 --- a/regex/matching.go +++ b/regex/matching.go @@ -319,7 +319,7 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in if currentState.contentContains(str, idx, preferLongest) { nextStates = addStateToList(str, idx+1, nextStates, *currentState.next, currentState.threadGroups, nil, preferLongest) } - } else if currentState.isBackreference { + } else if currentState.isBackreference && currentState.threadGroups[currentState.referredGroup].IsValid() { groupLength := currentState.threadGroups[currentState.referredGroup].EndIdx - currentState.threadGroups[currentState.referredGroup].StartIdx if currentState.threadBackref == groupLength { currentState.threadBackref = 0