regexp-tree icon indicating copy to clipboard operation
regexp-tree copied to clipboard

NFA/DFA: support explicit ^ and $ assertions

Open DmitrySoshnikov opened this issue 8 years ago • 0 comments

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 $)

DmitrySoshnikov avatar Oct 25 '17 00:10 DmitrySoshnikov