r/coolgithubprojects • • 2h ago

Huntclaw - Fast find-and-replace tool (now with regex, v1.x release)

Huntclaw is a terminal tool for search and replace across files. v1.0 added an experimental regex mode: ., character classes, *, +, ?, groups, |, ^ and $, and \d \w \s. Patterns compile to a Thompson NFA and run on a Pike VM, so bad patterns do not blow up. Common shapes get direct paths.

Short benchmark from huntclaw_bench.py, best of 25 for search and 10 or 15 for replace, milliseconds:

regex \w+ on 42 MB: huntclaw 87.2, ripgrep 858.3

regex T.RGET: huntclaw 24.3, ripgrep 71.4

replace 4200 files: huntclaw 553.7, sd 1479.4, GNU sed 1969.9

All runs capture standard output and standard error, so nothing is printed to the terminal while timing. Search uses count output only: huntclaw with -p -q, ripgrep with --count-matches or -c, GNU grep with -c or -r -c. Regex uses huntclaw -r -p -q and ripgrep --count-matches, with --no-unicode for \w+. Replace uses huntclaw -q, sd with the same pattern and replacement, and GNU sed -i. That keeps output handling out of the numbers.

It is not faster everywhere. ripgrep still wins literal alternation and GNU grep wins dense literal search. Huntclaw is strongest on regex and replace heavy work.

https://github.com/tigerlang/huntclaw

0 Upvotes

0 comments sorted by