|
5 | 5 | <link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
|
6 | 6 | <link href="https://learnbyexample.github.io"/>
|
7 | 7 | <generator uri="https://www.getzola.org/">Zola</generator>
|
8 |
| - <updated>2023-03-07T00:00:00+00:00</updated> |
| 8 | + <updated>2023-03-11T00:00:00+00:00</updated> |
9 | 9 | <id>https://learnbyexample.github.io/atom.xml</id>
|
| 10 | + <entry xml:lang="en"> |
| 11 | + <title>Python Regular Expressions Playground</title> |
| 12 | + <published>2023-03-11T00:00:00+00:00</published> |
| 13 | + <updated>2023-03-11T00:00:00+00:00</updated> |
| 14 | + <link rel="alternate" href="https://learnbyexample.github.io/python-regex-playground/" type="text/html"/> |
| 15 | + <id>https://learnbyexample.github.io/python-regex-playground/</id> |
| 16 | + <content type="html"><p>This TUI application is intended as an interactive playground for Python Regular Expressions. The app also includes a comprehensive cheatsheet and several interactive examples.</p> |
| 17 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexPlayground/pyregex_finditer.png" alt="Sample screenshot from the Playground screen" loading="lazy" /></p> |
| 18 | +<span id="continue-reading"></span><br> |
| 19 | +<h2 id="installation">Installation<a class="zola-anchor" href="#installation" aria-label="Anchor link for: installation">🔗</a></h2> |
| 20 | +<p>This app is available on PyPI as <a href="https://pypi.org/project/regexplayground/">regexplayground</a>. Example installation instructions are shown below, adjust them based on your preferences and OS.</p> |
| 21 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># virtual environment |
| 22 | +</span><span style="color:#5597d6;">$</span><span> python3</span><span style="color:#5597d6;"> -m</span><span> venv textual_apps |
| 23 | +</span><span style="color:#5597d6;">$</span><span> cd textual_apps |
| 24 | +</span><span style="color:#5597d6;">$</span><span> source bin/activate |
| 25 | +</span><span style="color:#5597d6;">$</span><span> pip install regexplayground |
| 26 | +</span><span> |
| 27 | +</span><span style="color:#7f8989;"># launch the app |
| 28 | +</span><span style="color:#5597d6;">$</span><span> regexplayground |
| 29 | +</span></code></pre> |
| 30 | +<p>To run the app without having to enter the virtual environment again, add this alias to <code>.bashrc</code> (or equivalent):</p> |
| 31 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># you&#39;ll have to change the path |
| 32 | +</span><span style="color:#b39f04;">alias </span><span style="color:#c23f31;">regexplayground</span><span style="color:#72ab00;">=</span><span style="color:#d07711;">&#39;/path/to/textual_apps/bin/regexplayground&#39; |
| 33 | +</span></code></pre> |
| 34 | +<p>As an alternative, you can install <code>textual</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 repository</a> and run the <code>pyregex_playground.py</code> file.</p> |
| 35 | +<p>Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's another screenshot:</p> |
| 36 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexPlayground/pyregex_examples.png" alt="Sample screenshot from the Interactive Examples screen" loading="lazy" /></p> |
| 37 | +<br> |
| 38 | +<h2 id="brief-guide">Brief Guide<a class="zola-anchor" href="#brief-guide" aria-label="Anchor link for: brief-guide">🔗</a></h2> |
| 39 | +<p>You can type the search pattern in the <strong>Compile</strong> input box and press the <strong>Enter</strong> key to execute. For example, <code>re.compile(r'\d')</code> to match digit characters. Matching portions will be highlighted in red.</p> |
| 40 | +<p>The compiled pattern is available via the <code>pat</code> variable and you can use <code>ip</code> to refer to the input string. You can transform or extract data by typing appropriate expression in the <strong>Action</strong> box. For example, <code>pat.sub(r'(\g&lt;0&gt;)', ip)</code> will add parenthesis around the matching portions.</p> |
| 41 | +<p>You can skip the Compile box and directly use the Action box too. For example, <code>[m.span() for m in re.finditer(r'\d+', ip)]</code> to get the location of all the matching portions.</p> |
| 42 | +<blockquote> |
| 43 | +<p><img src="/images/warning.svg" alt="warning" /> There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.</p> |
| 44 | +</blockquote> |
| 45 | +<p>Press <strong>F1</strong> to view the detailed guide from within the app, <strong>F2</strong> to view a cheatsheet and <strong>F3</strong> for interactive examples.</p> |
| 46 | +<p>For more detailed instructions, see <a href="https://github.com/learnbyexample/TUI-apps/blob/main/PyRegexPlayground/app_guide.md">app guide</a>.</p> |
| 47 | +<br> |
| 48 | +<h2 id="ebook">Ebook<a class="zola-anchor" href="#ebook" aria-label="Anchor link for: ebook">🔗</a></h2> |
| 49 | +<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> |
| 50 | +<br> |
| 51 | +<h2 id="feedback">Feedback<a class="zola-anchor" href="#feedback" aria-label="Anchor link for: feedback">🔗</a></h2> |
| 52 | +<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> |
| 53 | +<p>Hope you find this TUI app useful. Happy learning :)</p> |
| 54 | +</content> |
| 55 | + </entry> |
10 | 56 | <entry xml:lang="en">
|
11 | 57 | <title>CLI tip 24: inserting file contents one line at a time</title>
|
12 | 58 | <published>2023-03-07T00:00:00+00:00</published>
|
|
404 | 450 | <br>
|
405 | 451 | <h2 id="re-gex-playground">re(gex)? playground<a class="zola-anchor" href="#re-gex-playground" aria-label="Anchor link for: re-gex-playground">🔗</a></h2>
|
406 | 452 | <p>To make it easier to experiment, I'm working on an interactive app. See <a href="https://github.com/learnbyexample/TUI-apps/tree/main/PyRegexPlayground">PyRegexPlayground</a> repo for installation instructions and usage guide. A sample screenshot is shown below:</p>
|
407 |
| -<p align="center"><img src="https://learnbyexample.github.io/py_regular_expressions/images/pyregex_playground.png" alt="Python re(gex)? playground" loading="lazy" /></p> |
| 453 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexPlayground/pyregex_finditer.png" alt="Sample screenshot from the Playground screen" loading="lazy" /></p> |
408 | 454 | <br>
|
409 | 455 | <h2 id="table-of-contents">Table of Contents<a class="zola-anchor" href="#table-of-contents" aria-label="Anchor link for: table-of-contents">🔗</a></h2>
|
410 | 456 | <ol>
|
@@ -1085,7 +1131,7 @@ Specifying a greater than <code>0</code> start index when using
|
1085 | 1131 | <link rel="alternate" href="https://learnbyexample.github.io/interactive-linux-cli-exercises/" type="text/html"/>
|
1086 | 1132 | <id>https://learnbyexample.github.io/interactive-linux-cli-exercises/</id>
|
1087 | 1133 | <content type="html"><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/tree/main/CLI-Exercises">TUI app</a> has 40 beginner to intermediate level exercises for Linux CLI text processing tools.</p>
|
1088 |
| -<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/CLI-Exercises/cli_exercises.png" alt="Sample screenshot for CLI exercises" /></p> |
| 1134 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/CLI-Exercises/cli_exercises.png" alt="Sample screenshot for CLI exercises" loading="lazy" /></p> |
1089 | 1135 | <span id="continue-reading"></span><br>
|
1090 | 1136 | <h2 id="installation">Installation<a class="zola-anchor" href="#installation" aria-label="Anchor link for: installation">🔗</a></h2>
|
1091 | 1137 | <p>Last month, I started learning a Python TUI framework called <a href="https://textual.textualize.io/">Textual</a>. After working on a <a href="https://github.com/learnbyexample/TUI-apps/tree/main/SquareTicTacToe">4x4 board game</a>, I made an interactive app to help you test your CLI text processing skills with 40 beginner to intermediate level exercises. The app is fairly basic in terms of features — only single input file, so no stdin data, multiple files, etc.</p>
|
@@ -1117,7 +1163,7 @@ Specifying a greater than <code>0</code> start index when using
|
1117 | 1163 | <li>Press <strong>Ctrl+s</strong> to show the reference solution if you are unable to solve an exercise.</li>
|
1118 | 1164 | <li>Press <strong>Ctrl+t</strong> to toggle between light and dark themes.</li>
|
1119 | 1165 | <li>Press <strong>Ctrl+q</strong> to quit the app.</li>
|
1120 |
| -<li>Some basic emacs readline shortcuts are supported, like <strong>Ctrl+u</strong>, <strong>Ctrl+k</strong>, <strong>Ctrl+w</strong>, etc</li> |
| 1166 | +<li>Some basic readline-like shortcuts are supported, for example <strong>Ctrl+u</strong>, <strong>Ctrl+k</strong>, <strong>Ctrl+w</strong>, etc</li> |
1121 | 1167 | </ul>
|
1122 | 1168 | <p>Your progress is automatically saved and restored. Already answered questions will be skipped.</p>
|
1123 | 1169 | <blockquote>
|
|
0 commit comments