# re#
a grep that can search for multiple words at once and across paragraphs, powered by the [RE# regex engine](https://github.com/ieviev/resharp).
> `re#` is a valid binary name on unix - `#` only starts a comment after whitespace.
> also available as `resharp` for compatibility.
## Quickstart
```sh
re# 'TODO' src/ # search like ripgrep
re# -i 'fixme' . # case insensitive
re# -w 'error' -t rust # whole word, rust files only
### Multi-Word Search
`-W` finds lines containing all given words:
```sh
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:
```sh
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:
```sh
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).
```sh
# 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](https://ieviev.github.io/resharp-webapp/).
### Finding Leaked Keys
```sh
# 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.
```sh
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
| `-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](https://github.com/ieviev/resharp-cli/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)
```sh
chmod +x resharp-x86_64-linux
cp resharp-x86_64-linux ~/.local/bin/resharp
```
### Nix
```sh
nix profile install github:ieviev/resharp-cli
```
or in a flake:
```nix
inputs.resharp.url = "github:ieviev/resharp-cli";
```
the nix package also installs a `re#` symlink and shell completions.
### Cargo
```sh
cargo install resharp-grep # binary is named `resharp`
```
## License
MIT