Dev.to
7/20/2026

A Dart regex that cannot be made to hang
Short summary
Dart's default RegExp uses backtracking, making it vulnerable to ReDoS attacks where a 31-character input can take over 5 seconds. The re2 package provides FFI bindings to Google's RE2 library, which matches in linear time by rejecting backreferences and lookaround at construction time. Re2Set compiles multiple patterns into one automaton for single-pass matching, useful for rule engines and WAFs.
- •Dart's RegExp takes 5.15s on a 31-char ReDoS input; RE2 handles it in 25 microseconds
- •re2 package rejects backreferences/lookaround at construction, guaranteeing linear-time matching
- •Re2Set compiles multiple patterns into one automaton for efficient multi-pattern scanning
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



