resharp-grep 0.1.0

a grep-like grep tool powered by the resharp regex engine
resharp-grep-0.1.0 is not a library.

re#

a grep that can search for multiple words at once and across paragraphs, powered by the RE# regex engine.

install | web playground

re# is a valid binary name on unix - # only starts a comment after whitespace. also available as resharp for compatibility.

Quickstart

re# 'TODO' src/                       # search like ripgrep
re# -i 'fixme' .                      # case insensitive
re# -w 'error' -t rust                # whole word, rust files only
echo 'hello world' | re# 'hello'      # stdin

Multi-Word Search

-W finds lines containing all given words:

re# -W error -W timeout src/          # lines with both "error" AND "timeout"
re# -W error -W timeout -W retry .    # all three must appear

--not excludes lines matching a pattern:

re# -W error --not debug src/         # "error" without "debug"
re# -W error -W warn --not debug .    # "error" and "warn", but not "debug"

Paragraph Search

-p searches paragraphs (blocks separated by blank lines) instead of lines:

re# -p error -p timeout               # paragraphs containing both words
re# -p error -p timeout -t rust       # only in rust files
re# -i -p error -p timeout            # case insensitive

Regex Algebra

& (intersection) and ~ (complement) let you combine constraints in a single pattern. _ matches any character (like . but works across the algebra).

# hex strings that contain both a digit and a letter
re# '([0-9a-f]+)&(_*[0-9]_*)&(_*[a-f]_*)'

# lines with "error" AND "timeout" (same as -W, but inline)
re# '(_*error_*)&(_*timeout_*)'

# match identifiers 8-20 chars long containing "config"
re# '([a-zA-Z_]+)&(_{8,20})&(_*config_*)'

# complement: lines NOT containing "debug"
re# '~(_*debug_*)' src/

try patterns interactively in the web playground.

Finding Leaked Keys

# AWS keys
re# 'AKIA[A-Z0-9]{16}' .

# lines with key=value where the key name looks like a secret
re# '(_*(api_key|secret|token|password)_*)&(_*[=:]_*)' -i .

# github/gitlab/slack tokens
re# 'ghp_[A-Za-z0-9]+|glpat\-[A-Za-z0-9]+|xox[bp]\-[A-Za-z0-9\-]+' .

The Underscore

_ is the universal wildcard, not a literal underscore.

re# 'my_function'              # matches myXfunction, my.function, ...
re# 'my\_function'             # literal underscore
re# -R 'my_function'           # -R: raw regex mode, no algebra
re# -F 'my_function'           # -F: fixed string, no regex at all

Differences From Ripgrep

ripgrep re# why
-a / --text -uuu -a is taken by --and
_ is literal _ is wildcard use -R or \_ for literal
pattern is standard regex pattern has algebra &, ~, _ are operators; -R for compatibility mode

Exit Codes

0 match, 1 no match, 2 error

Install

Prebuilt Binaries

download from GitHub releases:

  • resharp-x86_64-linux (x86_64 linux)
  • resharp-aarch64-linux (aarch64 linux)
  • resharp-aarch64-macos (aarch64 macos)
  • resharp-x86_64-windows.exe (x86_64 windows)
chmod +x resharp-x86_64-linux
cp resharp-x86_64-linux ~/.local/bin/resharp

Nix

nix profile install github:ieviev/resharp-cli

or in a flake:

inputs.resharp.url = "github:ieviev/resharp-cli";

the nix package also installs a re# symlink and shell completions.

Cargo

cargo install resharp-grep  # binary is named `resharp`

License

MIT