-
Notifications
You must be signed in to change notification settings - Fork 26
lookaround support? #12
Comments
Not yet. I've started working on porting the logic to javascript (on the I think there's also an open research question which is what is the impact of negative lookahead on exponentially backtracking? |
Anything specific you need help on the js branch? I am a mantainer of markedjs which heavily uses regular expressions and I have been looking for a way to reliably check for ReDoS in our CI environment. This looks very promising but we would need support for look arounds. Also fixing whatever is wrong with this regexp
|
@UziTech I've not been able to get to it for a while, so if you are enthusiastic please feel free to jump in (though as I was trying to figure out the theory based on the paper and the ocaml, it may not be the easiest place to start!). I'd also take PRs to the original OCAML if you want to give that a try (though running it in CI was the use-case I wanted for which javascript would be much better, though you're welcome to hit the regex.rip API from your CI) As I mentioned above, there is still an open question that may make this change more involved than you hope: I do not know what impact look-around assertions have on the performance characteristics fo matching. I assume that:
One thing to note, is that v8 (the javascript engine in Chrome and chromium-based browsers) is fixing this problem properly: https://v8.dev/blog/non-backtracking-regexp but (sadly) only for regexes that don't include look-around. This is due to another open research question: can look-ahead and look-behind be implemented in a regex engine that does a single pass of the string and maintains only state in proportion to the size of the regex. (I'm pretty sure that positive and negative look-behind can be, but I haven't yet figured out a way to support look-ahead without storing more state, which breaks the runtime guarantees that re2 and thus v8 are aiming for) |
Just running them separately isn't going to work. For example:
I will have a look at this soon and see what I can find. Thanks |
Great counter-example, thank you! |
After a bit of research here is what I found:
So if we are going to check look arounds it seems we need to:
References: |
Thank you very much for contributing this and regex.rip.
I was wondering if it supports lookarounds (e.g. negative lookahead)?
I get an error message
Nfa.UnsupportedGroupingConstruct
The text was updated successfully, but these errors were encountered: