Python Regular Expressions Playground
This TUI application is intended as an interactive playground for Python Regular Expressions. The app also includes a comprehensive cheatsheet and several interactive examples.
Installation🔗
This app is available on PyPI as regexplayground. Example installation instructions are shown below, adjust them based on your preferences and OS.
# virtual environment
$ python3 -m venv textual_apps
$ cd textual_apps
$ source bin/activate
$ pip install regexplayground
# launch the app
$ regexplayground
To run the app without having to enter the virtual environment again, add this alias to .bashrc
(or equivalent):
# you'll have to change the path
alias regexplayground='/path/to/textual_apps/bin/regexplayground'
As an alternative, you can install textual
(see Textual documentation for more details), clone my TUI-apps repository and run the pyregex_playground.py
file.
Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's another screenshot:
Brief Guide🔗
You can type the search pattern in the Compile input box and press the Enter key to execute. For example, re.compile(r'\d')
to match digit characters. Matching portions will be highlighted in red.
The compiled pattern is available via the pat
variable and you can use ip
to refer to the input string. You can transform or extract data by typing appropriate expression in the Action box. For example, pat.sub(r'(\g<0>)', ip)
will add parenthesis around the matching portions.
You can skip the Compile box and directly use the Action box too. For example, [m.span() for m in re.finditer(r'\d+', ip)]
to get the location of all the matching portions.
There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.
Press F1 to view the detailed guide from within the app, F2 to view a cheatsheet and F3 for interactive examples.
For more detailed instructions, see app guide.
Ebook🔗
See my Understanding Python re(gex)? ebook to learn regular expressions with hundreds of examples and exercises.
Feedback🔗
I'd highly appreciate your feedback. Please file an issue if there are bugs, crashes, etc.
Hope you find this TUI app useful. Happy learning :)