regexp-tree
regexp-tree copied to clipboard
NFA/DFA: support explicit ^ and $ assertions
Currently NFA/DFA matcher tests for the entire string, as it would be treated as ^ ... $.
E.g., this matches:
fa.toDFA(/a/).matches('a'); // true
But this doesn't:
fa.toDFA(/a/).matches('ab'); // false
However, the later should match as well, since "a" character presents in the "ab" string.
So we should support explicit ^ and $ anchors in NFA/DFA interpreters. With this we should get:
fa.toDFA(/a/).matches('a'); // true
fa.toDFA(/a/).matches('ab'); // true
fa.toDFA(/^a$/).matches('a'); // true
fa.toDFA(/^a$/).matches('ab'); // false (as it is now without explicit ^ and $)