Skip to main content

A pure-python command-line regular expression tool for stream filtering, extracting, and parsing.

Project description

A pure-python command-line regular expression tool for stream filtering, and extracting, designed to be minimal with an intuitive command-line interface.


You can install this via

$ python3 -m pip install ret

or using pipx

$ pipx install ret

Ret is pure python (tested on python 3.6+) with no dependencies.

That way, you can get a clean uninstall.



You can use ret to extract text via regex capture groups:

$ git branch
* master
$ git branch | ret "\* (\w+)" s --group 1

…finding all occurrences of a pattern:

$ ls | ret ".*\.py" findall

and even all occurrences of a pattern with capture groups:

$ ls | ret "(.*)\.py" findall --group 1

While those may seem untypical use cases, I have found myself using Ret countless times.

Here’s a one-liner for uninstalling unnecessary stuff for pip:

$ pip list --not-required | ret ".+\n.+\n((?:\n|.)+)" f -g 1 | ret "([^\s]+)\s+.+\n" f -g 1 | xargs pip uninstall --yes

Another case

Imagine this: you have just downloaded a bunch of tarballs, and have ran

for x in $(grep ".+\.tar\.gz"); do tar -xzf $x; done

Now you just want to cd into all of the extracted files, run ./configure && make && make install.

You could use ret to get the names of the extracted files, just from the tarballs’ names. Like this:

$ ls | grep ".+\.tar\.gz"

$ ls | ret "(.+)\.tar\.gz" f -g 1

and with that combined, we can do

$ for x in (ls | ret "(.+)\.tar\.gz" f -g 1); do {
   cd $x &&
   ./configure && make && make install &&
   cd -}; done

A life saver.

And remember, this is python regex: a very powerful regular expression engine.

The possibilities of usage are endless.


Demonstration photo


I love grep. But grep isn’t really for text extraction.

For example, you cannot extract regexes via capture groups.

Since I wanted that functionality, I decided to build this, Ret.

Why the name?

Ret is an acronym for regular expression tool.

Why it can’t replace grep

Ret originally was designed to provide some features grep lacks. It never intended to replace good ol’ grep.

Grep is great for searching directories while ret (currently) can only read from a file or stdin.

Furthermore, you cannot guarantee that ret is installed on the machine.

Also, Ret relies on the (slow) python regex engine.

What about sed?

Sed is for find-and-replacing streams. Ret’s different. But together, you can do some powerful things

Feel free to contribute!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ret-0.1.4.tar.gz (18.3 kB view hashes)

Uploaded source

Built Distribution

ret-0.1.4-py3-none-any.whl (18.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page