From 5882aca3e3f6e8839a075654bd3b42e9ee93c4ac Mon Sep 17 00:00:00 2001 From: Koen Vossen Date: Thu, 18 Jun 2020 09:56:16 +0200 Subject: [PATCH] RegExp fix: already try to find longest match, but not only the last (prev_stack) one because that can't always terminate (can_terminate) --- .../services/matchers/pattern/regexp/regexp.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kloppy/domain/services/matchers/pattern/regexp/regexp.py b/kloppy/domain/services/matchers/pattern/regexp/regexp.py index 16940cec..db73daa7 100644 --- a/kloppy/domain/services/matchers/pattern/regexp/regexp.py +++ b/kloppy/domain/services/matchers/pattern/regexp/regexp.py @@ -601,7 +601,7 @@ def match( stack: List[Explorer[Tok, Out]] = [Explorer(self, _Initial(), tuple())] - prev_stack = None + stacks = [] for token in seq: stack = list( self._de_duplicate( @@ -616,10 +616,14 @@ def match( if not stack: break - prev_stack = stack + stacks.append(stack) - if not consume_all and prev_stack: - stack = [s for s in prev_stack if s.can_terminate()] + if not consume_all and stacks: + stacks.reverse() + for stack in stacks: + stack = [s for s in stack if s.can_terminate()] + if stack: + break terminal = list( self._de_duplicate(