Skip to content

wfxr/xre

Repository files navigation

xre

A fast regex extraction tool with pattern matching, replacement, and configurable sorting.

Features

  • 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

Installation

Quick Install

curl -fsSL https://raw.githubusercontent.com/wfxr/xre/main/install.sh | bash

Install 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/bin

From crates.io

cargo install xre

From source

cargo install --path .

From binaries

Download pre-built binaries from the releases page.

Usage

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

Examples

Basic URL extraction:

echo "visit https://example.com today" | xre -e 'https?://\S+'
# Output: https://example.com

Extract + replace (git SSH → HTTPS):

echo "git@github.com:wfxr/xre.git" | xre -e 'git@([^:]+):(.+)\.git' -r 'https://$1/$2'
# Output: https://github.com/wfxr/xre

Multi-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 appearance

License

Licensed under either of

at your option.

About

A fast regex extraction tool with pattern matching, replacement, and configurable sorting

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages