Having an interactive program that automatically loads questions and checks the solution is wonderful to have while learning a topic. This TUI app has beginner to advanced level exercises for Python regular expressions. There are more than 100 exercises covering both the builtin re and third-party regex module.

Sample screenshot for Python regex exercises


Installation🔗

This app is available on PyPI as regexexercises. 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 regexexercises

# launch the app
$ regexexercises

info If you are on Windows, using the Windows Terminal is recommended. See this issue for Virtual Environment commands and other details.

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 regexexercises='/path/to/textual_apps/bin/regexexercises'

As an alternative to manually managing such virtual environments, you can use https://github.com/pypa/pipx instead:

$ pipx install regexexercises
$ regexexercises

As yet another alternative, you can install textual (see Textual documentation for more details), clone my TUI-apps repository and run the pyregex_exercises.py file.

Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines).


Video demo🔗


Brief Guide🔗

  • Type your solution in the input box below the question.
    • Use ip variable to represent the sample input.
    • Any single valid Python expression will be accepted.
    • Some basic readline-like shortcuts are supported, for example Ctrl+u, Ctrl+k, Ctrl+w, etc
  • Press Enter to execute the code.
    • Output would be displayed below the command box.
    • If the output matches the expected results, the solution box will turn green and a reference solution will also be shown.
    • Error messages due to exceptions will be displayed in red.
  • Press Ctrl+p and Ctrl+n to navigate the questions list.
  • Press Ctrl+r to toggle between str and repr — helps to spot characters like tabs, newlines, backspaces, etc.
  • Press Ctrl+b to toggle between expected and actual — helps to debug incorrect solutions.
  • Press Ctrl+s to show the reference solution if you are unable to solve an exercise.
  • Press Ctrl+t to toggle between light and dark themes.
  • Press Ctrl+q to quit the app.
  • Press F1 to view a detailed guide within the app itself and press F2 to get back to the exercises.

Your progress will be automatically saved and restored. Already answered questions will be skipped.

warning There is no safeguard against the code you are executing. They are treated as if you executed them from a Python program.

See app_guide.md for more detailed instructions.


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 :)