A fast regex extraction tool with pattern matching, replacement, and configurable sorting.
- Multi-pattern extraction — apply multiple regex patterns in a single pass with priority ordering
- Match + replace — optional replacement templates with capture group substitution (
$1,$2, ...) - Deduplication — automatic dedup with first-occurrence tracking (disable with
--no-dedup) - Sorting — sort by appearance (default), frequency, or alphabetically
- Line numbers — optional line number prefix (
-n) - ANSI stripping — strip terminal escape sequences before processing (
--strip-ansi) - Line-oriented — input is processed line by line; each pattern matches within a single line
curl -fsSL https://raw.githubusercontent.com/wfxr/xre/main/install.sh | bashInstall a specific version or to a custom directory:
curl -fsSL https://raw.githubusercontent.com/wfxr/xre/main/install.sh | bash -s -- -v v0.1.0
curl -fsSL https://raw.githubusercontent.com/wfxr/xre/main/install.sh | bash -s -- -d /usr/local/bincargo install xrecargo install --path .Download pre-built binaries from the releases page.
xre [OPTIONS] [FILE]
Options:
-e, --extract <PATTERN> Extract pattern (repeatable, earlier = higher priority)
-r, --replace <REPLACEMENT> Replacement for the preceding -e ($1, $2, ...)
-s, --sort <STRATEGY> Sort strategy: appearance (default), frequency, alpha
--no-dedup Disable deduplication
-n, --line-number Prefix each match with line number (LINE:MATCH)
--strip-ansi Strip ANSI escape sequences before processing
-h, --help Print help
-V, --version Print version
Basic URL extraction:
echo "visit https://example.com today" | xre -e 'https?://\S+'
# Output: https://example.comExtract + replace (git SSH → HTTPS):
echo "git@github.com:wfxr/xre.git" | xre -e 'git@([^:]+):(.+)\.git' -r 'https://$1/$2'
# Output: https://github.com/wfxr/xreMulti-pattern with priority:
echo "visit https://www.example.com" | xre \
-e 'https?://\S+' \
-e '(www\.\S+)' -r 'http://$1'
# Output: https://www.example.com (second pattern skipped — range already consumed)tmux-fzf-url integration:
tmux capture-pane -J -p -e | xre --strip-ansi \
-e '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' \
-e 'git@([^:]+):(.+)\.git' -r 'https://$1/$2' \
-e '(www\.\S+)' -r 'http://$1' \
-s appearanceLicensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.