Skip to content

basic variable-sized lookbehind implementation#194

Merged
keith-hall merged 6 commits intomainfrom
variable_lookbehind_easy
Oct 31, 2025
Merged

basic variable-sized lookbehind implementation#194
keith-hall merged 6 commits intomainfrom
variable_lookbehind_easy

Conversation

@keith-hall
Copy link
Copy Markdown
Contributor

@keith-hall keith-hall commented Oct 15, 2025

use regex-automata's DFA reverse search functionality to support variable (even unbounded) length lookbehinds without fancy features or capture groups. Partially fixes #74

Added benchmarks demonstrating that const-size lookbehinds are more efficient:

const_size_lookbehind    (~154 ns)  - uses simple GoBack instruction
variable_size_lookbehind (~448 ns)  - uses reverse DFA search

The variable-size implementation is about 3x slower but still very fast (sub-microsecond), confirming that the const-size optimization continues to work correctly and is worth keeping.

I created a feature flag for this, but I wasn't sure whether it should be part of the default features or not. Oniguruma does apparently support this, so I included it in the default features for now, but if someone has arguments for removing it, I'm happy to hear them.

use regex-automata's DFA reverse search functionality to support variable (even unbounded) length lookbehinds without fancy features or capture groups
- also improve error handling for when it fails to build a DFA
- add benchmarks
- update docs to mention the feature flag
- which allows us to have a debug formatting implementation for use in the toy example and playground
…okbehind

if it matches once, it doesn't matter whether it will match more times or not, the end result is unaffected
@keith-hall keith-hall marked this pull request as ready for review October 17, 2025 21:06
@keith-hall keith-hall requested a review from robinst October 17, 2025 21:08
Copy link
Copy Markdown
Contributor

@robinst robinst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one suggestion. Nice work!

@keith-hall keith-hall merged commit b58fb31 into main Oct 31, 2025
7 of 9 checks passed
@keith-hall keith-hall deleted the variable_lookbehind_easy branch December 13, 2025 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support look-behind assertions without constant size

2 participants