diff --git a/assembly/__tests__/capture-group.spec.ts b/assembly/__tests__/capture-group.spec.ts index e8ff9c0..ee4fe4a 100644 --- a/assembly/__tests__/capture-group.spec.ts +++ b/assembly/__tests__/capture-group.spec.ts @@ -33,3 +33,9 @@ it("should not return captured values for non-matching alternations", () => { expect(match.matches[1]).toBe(""); expect(match.matches[2]).toBe("b"); }); + +it("repeated capture groups should return the last match", () => { + const match = exec("([a-c])+", "ac"); + expect(match.matches[0]).toBe("ac"); + expect(match.matches[1]).toBe("c"); +}); diff --git a/assembly/nfa/walker.ts b/assembly/nfa/walker.ts index 276d123..9404f33 100644 --- a/assembly/nfa/walker.ts +++ b/assembly/nfa/walker.ts @@ -5,8 +5,8 @@ export function walker( visitor: (state: State) => void, visited: State[] = [] ): void { - visitor(state); if (visited.includes(state)) return; + visitor(state); visited.push(state); const nextStates = state.transitions; for (let i = 0, len = nextStates.length; i < len; i++) {