Skip to main content
https://codecov.io/gh/ThatXliner/ret/branch/master/graph/badge.svg?token=6B5AWYTL1O

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

Installation

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.

Usage

Example

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

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

…finding all occurrences of a pattern:

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

and even all occurrences of a pattern with capture groups:

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

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"
foo.tar.gz
bar.tar.gz
foobar.tar.gz
extractme.tar.gz


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

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

Demonstration photo

Background

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!

Release files for ret 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ret 0.1.4
File Size Uploaded
ret-0.1.4.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ret 0.1.4
File Interpreter ABI Platform
ret-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 36.6 kB

Release files / ret-0.1.4.tar.gz

Download URL ret-0.1.4.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3a6709a3833629b92a8088be347f55c63ff6163231e40dede3974ef1a00c455e
BLAKE2b-256 checksum
How to use checksums
8a8729e367f36b5a89d8a9614cced30358505fea2a65778ced9d03c313505a9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

Release files / ret-0.1.4-py3-none-any.whl

Download URL ret-0.1.4-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14387783f7ff51415f4fe8ba4963a09b6f48c87eec15a58c48d03a1bf06c193f
BLAKE2b-256 checksum
How to use checksums
0da52516c8847a8f147d83de014af0f1aaac519212fa5d936594f766214c5af6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page