-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.html
13 lines (13 loc) Β· 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>100+ Interactive Python Regex Exercises</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="100+ Interactive Python Regex Exercises" property=og:title><meta content=website property=og:type><meta content="Practice Python regular expressions interactively, includes both re and regex modules" property=og:description><meta content=https://learnbyexample.github.io/interactive-python-regex-exercises/ property=og:url><meta content=https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexExercises/pyregex_exercises.png property=og:image><meta content=1088 property=og:image:width><meta content=641 property=og:image:height><meta content=summary_large_image property=twitter:card><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/interactive-python-regex-exercises/#installation>Installation</a><li><a class=toc-link href=https://learnbyexample.github.io/interactive-python-regex-exercises/#video-demo>Video demo</a><li><a class=toc-link href=https://learnbyexample.github.io/interactive-python-regex-exercises/#brief-guide>Brief Guide</a><li><a class=toc-link href=https://learnbyexample.github.io/interactive-python-regex-exercises/#ebook>Ebook</a><li><a class=toc-link href=https://learnbyexample.github.io/interactive-python-regex-exercises/#feedback>Feedback</a></ul></nav></div></div><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/interactive-python-regex-exercises/>100+ Interactive Python Regex Exercises</a></h1><div class=post__meta><span class=post__time>2023-03-20</span></div></header><div class=post-content><p>Having an interactive program that automatically loads questions and checks the solution is wonderful to have while learning a topic. This <a href=https://github.com/learnbyexample/TUI-apps/blob/main/PyRegexExercises>TUI app</a> has beginner to advanced level exercises for Python regular expressions. There are more than 100 exercises covering both the builtin <code>re</code> and third-party <code>regex</code> module.<p align=center><img alt="Sample screenshot for Python regex exercises" loading=lazy src=https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexExercises/pyregex_exercises.png></p><span id=continue-reading></span><br><h2 id=installation>Installation<a aria-label="Anchor link for: installation" class=zola-anchor href=#installation>π</a></h2><p>This app is available on PyPI as <a href=https://pypi.org/project/regexexercises/>regexexercises</a>. Example installation instructions are shown below, adjust them based on your preferences and OS.<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#7f8989;># virtual environment
</span><span style=color:#5597d6;>$</span><span> python3</span><span style=color:#5597d6;> -m</span><span> venv textual_apps
</span><span style=color:#5597d6;>$</span><span> cd textual_apps
</span><span style=color:#5597d6;>$</span><span> source bin/activate
</span><span style=color:#5597d6;>$</span><span> pip install regexexercises
</span><span>
</span><span style=color:#7f8989;># launch the app
</span><span style=color:#5597d6;>$</span><span> regexexercises
</span></code></pre><blockquote><p><img alt=info src=/images/info.svg> If you are on Windows, using the <a href=https://en.wikipedia.org/wiki/Windows_Terminal>Windows Terminal</a> is recommended. See <a href=https://github.com/learnbyexample/TUI-apps/issues/3#issuecomment-1481488042>this issue</a> for Virtual Environment commands and other details.</blockquote><p>To run the app without having to enter the virtual environment again, add this alias to <code>.bashrc</code> (or equivalent):<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#7f8989;># you'll have to change the path
</span><span style=color:#b39f04;>alias </span><span style=color:#c23f31;>regexexercises</span><span style=color:#72ab00;>=</span><span style=color:#d07711;>'/path/to/textual_apps/bin/regexexercises'
</span></code></pre><p>As an alternative to manually managing such virtual environments, you can use <a href=https://github.com/pypa/pipx>https://github.com/pypa/pipx</a> instead:<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#5597d6;>$</span><span> pipx install regexexercises
</span><span style=color:#5597d6;>$</span><span> regexexercises
</span></code></pre><p>As yet another alternative, you can install <code>textual==0.85.2</code> (see <a href=https://textual.textualize.io/getting_started/>Textual documentation</a> for more details), clone my <a href=https://github.com/learnbyexample/TUI-apps>TUI-apps</a> repository and run the <code>pyregex_exercises.py</code> file.<p>Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines).</p><br><h2 id=video-demo>Video demo<a aria-label="Anchor link for: video-demo" class=zola-anchor href=#video-demo>π</a></h2><p align=center><iframe allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="YouTube video player" allowfullscreen frameborder=0 height=315 loading=lazy src=https://www.youtube.com/embed/0oXPeF8HutQ width=560></iframe></p><br><h2 id=brief-guide>Brief Guide<a aria-label="Anchor link for: brief-guide" class=zola-anchor href=#brief-guide>π</a></h2><ul><li>Type your solution in the input box below the question. <ul><li>Use <code>ip</code> variable to represent the sample input.<li>Any single valid Python expression will be accepted.<li>Some basic readline-like shortcuts are supported, for example <strong>Ctrl+u</strong>, <strong>Ctrl+k</strong>, <strong>Ctrl+w</strong>, etc</ul><li>Press <strong>Enter</strong> to execute the code. <ul><li>Output would be displayed below the command box.<li>If the output matches the expected results, the solution box will turn <em>green</em> and a reference solution will also be shown.<li>Error messages due to exceptions will be displayed in <em>red</em>.</ul><li>Press <strong>Ctrl+p</strong> and <strong>Ctrl+n</strong> to navigate the questions list.<li>Press <strong>Ctrl+r</strong> to toggle between <strong>str</strong> and <strong>repr</strong> β helps to spot characters like tabs, newlines, backspaces, etc.<li>Press <strong>Ctrl+b</strong> to toggle between <strong>expected</strong> and <strong>actual</strong> β helps to debug incorrect solutions.<li>Press <strong>Ctrl+s</strong> toggle reference solution<li>Press <strong>Ctrl+t</strong> to toggle between light and dark themes.<li>Press <strong>Ctrl+q</strong> to quit the app.<li>Press <strong>F1</strong> to view a detailed guide within the app itself and press <strong>F2</strong> to get back to the exercises.</ul><p>Your progress will be automatically saved and restored. Already answered questions will be skipped.<blockquote><p><img alt=warning src=/images/warning.svg> There is no safeguard against the code you are executing. They are treated as if you executed them from a Python program.</blockquote><p>See <a href=https://github.com/learnbyexample/TUI-apps/blob/main/PyRegexExercises/app_guide.md>app_guide.md</a> for more detailed instructions.</p><br><h2 id=ebook>Ebook<a aria-label="Anchor link for: ebook" class=zola-anchor href=#ebook>π</a></h2><p>See my <a href=https://github.com/learnbyexample/py_regular_expressions>Understanding Python re(gex)?</a> ebook to learn regular expressions with hundreds of examples and exercises.</p><br><h2 id=feedback>Feedback<a aria-label="Anchor link for: feedback" class=zola-anchor href=#feedback>π</a></h2><p>I'd highly appreciate your feedback. Please file <a href=https://github.com/learnbyexample/TUI-apps/issues>an issue</a> if there are bugs, crashes, etc.<p>Hope you find this TUI app useful. Happy learning :)</div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/python/>#python</a><a href=https://learnbyexample.github.io/tags/regular-expressions/>#regular-expressions</a><a href=https://learnbyexample.github.io/tags/exercises/>#exercises</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=previous href=https://learnbyexample.github.io/cli-text-processing-grep-announcement/>β CLI text processing with GNU grep and ripgrep book announcement</a><br><p><a class=next href=https://learnbyexample.github.io/python-regex-playground/>Python Regular Expressions Playground β</a><br></div><hr color=#e6e6e6><p>π° Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> β
Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> π§ Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>