Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stuarthicks/rextract
Simple shell regex capture extractor
https://github.com/stuarthicks/rextract
cli go golang regex regular-expression regular-expressions
Last synced: 4 days ago
JSON representation
Simple shell regex capture extractor
- Host: GitHub
- URL: https://github.com/stuarthicks/rextract
- Owner: stuarthicks
- License: mit
- Created: 2024-03-14T15:04:43.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-05-28T15:45:55.000Z (8 months ago)
- Last Synced: 2024-06-21T14:11:42.927Z (7 months ago)
- Topics: cli, go, golang, regex, regular-expression, regular-expressions
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rextract
Simple shell regex capture extractor. Processes STDIN and matches using the provided regex. The first capture group defined in the regex is printed to STDOUT (or a specific named group using `-g`).
## Why?
This is nothing new, and can be achieved with many other tools such as Perl, Sed, etc. However I often struggle to remember the specific flags and quirks of those tools, especially when switching between BSD and Linux based systems. This tool is as simple as I've always wanted this "regex extractor" functionality to be.
## Install
Using Homebrew:
brew install stuarthicks/brews/rextract
Using Go:
go install github.com/stuarthicks/rextract@latest
## Usage
Usage of rextract:
-e string
A regular expression to match against stdin (default ".")
-g string
Extract this named capture group instead of the first capture## Examples
echo 'foobarbat' | rextract -e '(bar)' # prints 'bar'
echo 'foobarbat' | rextract -e '(foo)(bar)' # prints 'foo'
echo 'foobarbat' | rextract -e '(?Pfoo)(?Pbar)' -g two # prints 'bar'