diff --git a/nfa.go b/nfa.go index 37d67d3..31cdcfc 100644 --- a/nfa.go +++ b/nfa.go @@ -122,13 +122,21 @@ func (s State) checkAssertion(str []rune, idx int) bool { // 2. Run it on a subset of the test string, that ends after the current index in the string // 3. Based on the kind of lookaround (and the indices we get), determine what action to take. startState := s.lookaroundNFA - var strToMatch []rune + var runesToMatch []rune + var strToMatch string if s.assert == PLA || s.assert == NLA { - strToMatch = str[idx:] + runesToMatch = str[idx:] } else { - strToMatch = str[:idx] + runesToMatch = str[:idx] } - matchIndices := findAllMatches(startState, strToMatch, startState.lookaroundNumCaptureGroups) + + if len(runesToMatch) == 0 { + strToMatch = "" + } else { + strToMatch = string(runesToMatch) + } + + matchIndices := findAllMatches(Reg{startState, startState.lookaroundNumCaptureGroups}, strToMatch) numMatchesFound := 0 for _, matchIdx := range matchIndices {