From b60ded41366a9e57b3a911a2770c50f11d856f4d Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 9 Feb 2025 15:48:33 -0500 Subject: [PATCH] Don't break when a match is found, if we are looking for the longest match --- regex/matching.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/regex/matching.go b/regex/matching.go index 4d7c600..0787572 100644 --- a/regex/matching.go +++ b/regex/matching.go @@ -287,7 +287,9 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in if currentState.isLast { currentState.threadGroups[0].EndIdx = idx match = append([]Group{}, currentState.threadGroups...) - break + if !preferLongest { + break + } } else if !currentState.isAlternation && !currentState.isKleene && !currentState.isQuestion && !currentState.groupBegin && !currentState.groupEnd && currentState.assert == noneAssert { // Normal character if currentState.contentContains(str, idx, preferLongest) { nextStates = addStateToList(str, idx+1, nextStates, *currentState.next, currentState.threadGroups, nil, preferLongest)