From cda0dfb0ccc2a78ffa7f71f82fb313644826076a Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 27 Oct 2024 15:11:12 -0400 Subject: [PATCH] Match empty string if start state is kleene star --- matching.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matching.go b/matching.go index 5afe6ca..52de354 100644 --- a/matching.go +++ b/matching.go @@ -31,6 +31,10 @@ func findAllMatches(start *State, str string) (indices []matchIndex) { func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset int) []matchIndex { // 'Base case' - exit if string is empty. if len(str) == 0 { + // If the start is a Kleene star, then it should also match an empty string. + if start.isKleene { + indices = append(indices, matchIndex{offset, offset}) + } return indices }