Skip to content

Commit d1f909b

Browse files
committedMar 20, 2023
added post for interactive python regex exercises
1 parent f86b317 commit d1f909b

File tree

14 files changed

+98
-15
lines changed

14 files changed

+98
-15
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
66

77
## Posts
88

9+
* [100+ Interactive Python Regex Exercises](https://learnbyexample.github.io/interactive-python-regex-exercises/)
910
* [Python Regular Expressions Playground](https://learnbyexample.github.io/python-regex-playground/)
1011
* [Understanding Python re(gex)? book announcement](https://learnbyexample.github.io/understanding-python-regex-announcement/)
1112
* [Python Regex Surprises](https://learnbyexample.github.io/python-regex-surprises/)

‎atom.xml

+71-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,73 @@
55
<link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
66
<link href="https://learnbyexample.github.io"/>
77
<generator uri="https://www.getzola.org/">Zola</generator>
8-
<updated>2023-03-15T00:00:00+00:00</updated>
8+
<updated>2023-03-20T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>100+ Interactive Python Regex Exercises</title>
12+
<published>2023-03-20T00:00:00+00:00</published>
13+
<updated>2023-03-20T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/interactive-python-regex-exercises/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/interactive-python-regex-exercises/</id>
16+
<content type="html">&lt;p&gt;Having an interactive program that automatically loads questions and checks the solution is wonderful to have while learning a topic. This &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;TUI-apps&#x2F;blob&#x2F;main&#x2F;PyRegexExercises&quot;&gt;TUI app&lt;&#x2F;a&gt; has beginner to advanced level exercises for Python regular expressions. There are more than 100 exercises covering both the builtin &lt;code&gt;re&lt;&#x2F;code&gt; and third-party &lt;code&gt;regex&lt;&#x2F;code&gt; module.&lt;&#x2F;p&gt;
17+
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;learnbyexample&#x2F;TUI-apps&#x2F;main&#x2F;PyRegexExercises&#x2F;pyregex_exercises.png&quot; alt=&quot;Sample screenshot for Python regex exercises&quot; loading=&quot;lazy&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
18+
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;br&gt;
19+
&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;a class=&quot;zola-anchor&quot; href=&quot;#installation&quot; aria-label=&quot;Anchor link for: installation&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
20+
&lt;p&gt;This app is available on PyPI as &lt;a href=&quot;https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;regexexercises&#x2F;&quot;&gt;regexexercises&lt;&#x2F;a&gt;. Example installation instructions are shown below, adjust them based on your preferences and OS.&lt;&#x2F;p&gt;
21+
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# virtual environment
22+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; python3&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt; -m&lt;&#x2F;span&gt;&lt;span&gt; venv textual_apps
23+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; cd textual_apps
24+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; source bin&#x2F;activate
25+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; pip install regexexercises
26+
&lt;&#x2F;span&gt;&lt;span&gt;
27+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# launch the app
28+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; regexexercises
29+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
30+
&lt;p&gt;To run the app without having to enter the virtual environment again, add this alias to &lt;code&gt;.bashrc&lt;&#x2F;code&gt; (or equivalent):&lt;&#x2F;p&gt;
31+
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# you&amp;#39;ll have to change the path
32+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;alias &lt;&#x2F;span&gt;&lt;span style=&quot;color:#c23f31;&quot;&gt;regexexercises&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&#x2F;path&#x2F;to&#x2F;textual_apps&#x2F;bin&#x2F;regexexercises&amp;#39;
33+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
34+
&lt;p&gt;As an alternative, you can install &lt;code&gt;textual&lt;&#x2F;code&gt; (see &lt;a href=&quot;https:&#x2F;&#x2F;textual.textualize.io&#x2F;getting_started&#x2F;&quot;&gt;Textual documentation&lt;&#x2F;a&gt; for more details), clone my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;TUI-apps&quot;&gt;TUI-apps&lt;&#x2F;a&gt; repository and run the &lt;code&gt;pyregex_exercises.py&lt;&#x2F;code&gt; file.&lt;&#x2F;p&gt;
35+
&lt;p&gt;Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines).&lt;&#x2F;p&gt;
36+
&lt;br&gt;
37+
&lt;h2 id=&quot;brief-guide&quot;&gt;Brief Guide&lt;a class=&quot;zola-anchor&quot; href=&quot;#brief-guide&quot; aria-label=&quot;Anchor link for: brief-guide&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
38+
&lt;ul&gt;
39+
&lt;li&gt;Type your solution in the input box below the question.
40+
&lt;ul&gt;
41+
&lt;li&gt;Use &lt;code&gt;ip&lt;&#x2F;code&gt; variable to represent the sample input.&lt;&#x2F;li&gt;
42+
&lt;li&gt;Any single valid Python expression will be accepted.&lt;&#x2F;li&gt;
43+
&lt;li&gt;Some basic readline-like shortcuts are supported, for example &lt;strong&gt;Ctrl+u&lt;&#x2F;strong&gt;, &lt;strong&gt;Ctrl+k&lt;&#x2F;strong&gt;, &lt;strong&gt;Ctrl+w&lt;&#x2F;strong&gt;, etc&lt;&#x2F;li&gt;
44+
&lt;&#x2F;ul&gt;
45+
&lt;&#x2F;li&gt;
46+
&lt;li&gt;Press &lt;strong&gt;Enter&lt;&#x2F;strong&gt; to execute the code.
47+
&lt;ul&gt;
48+
&lt;li&gt;Output would be displayed below the command box.&lt;&#x2F;li&gt;
49+
&lt;li&gt;If the output matches the expected results, the solution box will turn &lt;em&gt;green&lt;&#x2F;em&gt; and a reference solution will also be shown.&lt;&#x2F;li&gt;
50+
&lt;li&gt;Error messages due to exceptions will be displayed in &lt;em&gt;red&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
51+
&lt;&#x2F;ul&gt;
52+
&lt;&#x2F;li&gt;
53+
&lt;li&gt;Press &lt;strong&gt;Ctrl+p&lt;&#x2F;strong&gt; and &lt;strong&gt;Ctrl+n&lt;&#x2F;strong&gt; to navigate the questions list.&lt;&#x2F;li&gt;
54+
&lt;li&gt;Press &lt;strong&gt;Ctrl+r&lt;&#x2F;strong&gt; to toggle between &lt;strong&gt;str&lt;&#x2F;strong&gt; and &lt;strong&gt;repr&lt;&#x2F;strong&gt; — helps to spot characters like tabs, newlines, backspaces, etc.&lt;&#x2F;li&gt;
55+
&lt;li&gt;Press &lt;strong&gt;Ctrl+b&lt;&#x2F;strong&gt; to toggle between &lt;strong&gt;expected&lt;&#x2F;strong&gt; and &lt;strong&gt;actual&lt;&#x2F;strong&gt; — helps to debug incorrect solutions.&lt;&#x2F;li&gt;
56+
&lt;li&gt;Press &lt;strong&gt;Ctrl+s&lt;&#x2F;strong&gt; to show the reference solution if you are unable to solve an exercise.&lt;&#x2F;li&gt;
57+
&lt;li&gt;Press &lt;strong&gt;Ctrl+t&lt;&#x2F;strong&gt; to toggle between light and dark themes.&lt;&#x2F;li&gt;
58+
&lt;li&gt;Press &lt;strong&gt;Ctrl+q&lt;&#x2F;strong&gt; to quit the app.&lt;&#x2F;li&gt;
59+
&lt;li&gt;Press &lt;strong&gt;F1&lt;&#x2F;strong&gt; to view a detailed guide within the app itself and press &lt;strong&gt;F2&lt;&#x2F;strong&gt; to get back to the exercises.&lt;&#x2F;li&gt;
60+
&lt;&#x2F;ul&gt;
61+
&lt;p&gt;Your progress will be automatically saved and restored. Already answered questions will be skipped.&lt;&#x2F;p&gt;
62+
&lt;blockquote&gt;
63+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;warning.svg&quot; alt=&quot;warning&quot; &#x2F;&gt; There is no safeguard against the code you are executing. They are treated as if you executed them from a Python program.&lt;&#x2F;p&gt;
64+
&lt;&#x2F;blockquote&gt;
65+
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;TUI-apps&#x2F;blob&#x2F;main&#x2F;PyRegexExercises&#x2F;app_guide.md&quot;&gt;app_guide.md&lt;&#x2F;a&gt; for more detailed instructions.&lt;&#x2F;p&gt;
66+
&lt;br&gt;
67+
&lt;h2 id=&quot;ebook&quot;&gt;Ebook&lt;a class=&quot;zola-anchor&quot; href=&quot;#ebook&quot; aria-label=&quot;Anchor link for: ebook&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
68+
&lt;p&gt;See my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&quot;&gt;Understanding Python re(gex)?&lt;&#x2F;a&gt; ebook to learn regular expressions with hundreds of examples and exercises.&lt;&#x2F;p&gt;
69+
&lt;br&gt;
70+
&lt;h2 id=&quot;feedback&quot;&gt;Feedback&lt;a class=&quot;zola-anchor&quot; href=&quot;#feedback&quot; aria-label=&quot;Anchor link for: feedback&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
71+
&lt;p&gt;I&#x27;d highly appreciate your feedback. Please file &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;TUI-apps&#x2F;issues&quot;&gt;an issue&lt;&#x2F;a&gt; if there are bugs, crashes, etc.&lt;&#x2F;p&gt;
72+
&lt;p&gt;Hope you find this TUI app useful. Happy learning :)&lt;&#x2F;p&gt;
73+
</content>
74+
</entry>
1075
<entry xml:lang="en">
1176
<title>Vim tip 23: editing lines filtered by a pattern</title>
1277
<published>2023-03-14T00:00:00+00:00</published>
@@ -4753,10 +4818,12 @@ Specifying a greater than &lt;code&gt;0&lt;&#x2F;code&gt; start index when using
47534818
<entry xml:lang="en">
47544819
<title>Improve your Python regex skills with 75 interactive exercises</title>
47554820
<published>2021-12-01T00:00:00+00:00</published>
4756-
<updated>2022-12-09T00:00:00+00:00</updated>
4821+
<updated>2023-03-20T00:00:00+00:00</updated>
47574822
<link rel="alternate" href="https://learnbyexample.github.io/python-25-days-of-regex/" type="text/html"/>
47584823
<id>https://learnbyexample.github.io/python-25-days-of-regex/</id>
4759-
<content type="html">&lt;p&gt;Still confused about Python regular expressions? Grow your confidence with &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&quot;&gt;Understanding Python re(gex)?&lt;&#x2F;a&gt; ebook (FREE this month!) and an &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&#x2F;tree&#x2F;master&#x2F;interactive_exercises&quot;&gt;interactive GUI app&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
4824+
<content type="html">&lt;p&gt;&lt;strong&gt;(2023-03-20) Update:&lt;&#x2F;strong&gt; This &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;TUI-apps&#x2F;blob&#x2F;main&#x2F;PyRegexExercises&quot;&gt;TUI app&lt;&#x2F;a&gt; covers many more exercises compared to the GUI app discussed below.&lt;&#x2F;p&gt;
4825+
&lt;hr&gt;
4826+
&lt;p&gt;Still confused about Python regular expressions? Grow your confidence with &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&quot;&gt;Understanding Python re(gex)?&lt;&#x2F;a&gt; ebook (FREE this month!) and an &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&#x2F;tree&#x2F;8433b34bd3f03662abac25c754a5ecf871712980&#x2F;interactive_exercises&quot;&gt;interactive GUI app&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
47604827
&lt;p&gt;Inspired by &lt;a href=&quot;https:&#x2F;&#x2F;adventofcode.com&#x2F;&quot;&gt;Advent of Code&lt;&#x2F;a&gt;, I&#x27;ll also be posting &lt;a href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;learn_byexample&#x2F;status&#x2F;1465998844898918403&quot;&gt;3 challenges per day on twitter&lt;&#x2F;a&gt; for 25 days.&lt;&#x2F;p&gt;
47614828
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;br&gt;
47624829
&lt;h2 id=&quot;free-ebook&quot;&gt;Free ebook&lt;a class=&quot;zola-anchor&quot; href=&quot;#free-ebook&quot; aria-label=&quot;Anchor link for: free-ebook&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
@@ -4768,7 +4835,7 @@ Specifying a greater than &lt;code&gt;0&lt;&#x2F;code&gt; start index when using
47684835
&lt;p&gt;Or, you can use the &lt;a href=&quot;https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;py_regular_expressions&#x2F;&quot;&gt;web version&lt;&#x2F;a&gt; if you prefer reading the book online.&lt;&#x2F;p&gt;
47694836
&lt;br&gt;
47704837
&lt;h2 id=&quot;interactive-gui-app&quot;&gt;Interactive GUI app&lt;a class=&quot;zola-anchor&quot; href=&quot;#interactive-gui-app&quot; aria-label=&quot;Anchor link for: interactive-gui-app&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
4771-
&lt;p&gt;Based on the &lt;strong&gt;Understanding Python re(gex)?&lt;&#x2F;strong&gt; book contents as well as the exercises, I made an &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&#x2F;tree&#x2F;master&#x2F;interactive_exercises&quot;&gt;interactive GUI app&lt;&#x2F;a&gt; with 75 questions on &lt;code&gt;re.search&lt;&#x2F;code&gt;, &lt;code&gt;re.sub&lt;&#x2F;code&gt;, &lt;code&gt;re.split&lt;&#x2F;code&gt; and &lt;code&gt;re.findall&lt;&#x2F;code&gt; that&#x27;ll test your understanding of anchors, alternation, grouping, escaping metacharacters, dot metacharacter, quantifiers, character class, grouping, lookarounds, flags, etc.&lt;&#x2F;p&gt;
4838+
&lt;p&gt;Based on the &lt;strong&gt;Understanding Python re(gex)?&lt;&#x2F;strong&gt; book contents as well as the exercises, I made an &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;py_regular_expressions&#x2F;tree&#x2F;8433b34bd3f03662abac25c754a5ecf871712980&#x2F;interactive_exercises&quot;&gt;interactive GUI app&lt;&#x2F;a&gt; with 75 questions on &lt;code&gt;re.search&lt;&#x2F;code&gt;, &lt;code&gt;re.sub&lt;&#x2F;code&gt;, &lt;code&gt;re.split&lt;&#x2F;code&gt; and &lt;code&gt;re.findall&lt;&#x2F;code&gt; that&#x27;ll test your understanding of anchors, alternation, grouping, escaping metacharacters, dot metacharacter, quantifiers, character class, grouping, lookarounds, flags, etc.&lt;&#x2F;p&gt;
47724839
&lt;p&gt;Here&#x27;s some screenshots:&lt;&#x2F;p&gt;
47734840
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;&#x2F;images&#x2F;python_exercises&#x2F;search.png&quot; alt=&quot;Python exercise example for re.search&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
47744841
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;&#x2F;images&#x2F;python_exercises&#x2F;sub.png&quot; alt=&quot;Python exercise example for re.sub&quot; &#x2F;&gt;&lt;&#x2F;p&gt;

‎index.html

+1-1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!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/#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
2+
</span><span style=color:#5597d6;>$</span><span> python3</span><span style=color:#5597d6;> -m</span><span> venv textual_apps
3+
</span><span style=color:#5597d6;>$</span><span> cd textual_apps
4+
</span><span style=color:#5597d6;>$</span><span> source bin/activate
5+
</span><span style=color:#5597d6;>$</span><span> pip install regexexercises
6+
</span><span>
7+
</span><span style=color:#7f8989;># launch the app
8+
</span><span style=color:#5597d6;>$</span><span> regexexercises
9+
</span></code></pre><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
10+
</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'
11+
</span></code></pre><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</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=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> to show the reference solution if you are unable to solve an exercise.<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=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>

‎page/2/index.html

+1-1
Large diffs are not rendered by default.

‎page/3/index.html

+1-1
Large diffs are not rendered by default.

‎page/4/index.html

+1-1
Large diffs are not rendered by default.

‎python-25-days-of-regex/index.html

+1-1
Large diffs are not rendered by default.

‎python-regex-playground/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
</span><span style=color:#5597d6;>$</span><span> regexplayground
99
</span></code></pre><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
1010
</span><span style=color:#b39f04;>alias </span><span style=color:#c23f31;>regexplayground</span><span style=color:#72ab00;>=</span><span style=color:#d07711;>'/path/to/textual_apps/bin/regexplayground'
11-
</span></code></pre><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>Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's another screenshot:<p align=center><img alt="Sample screenshot from the Interactive Examples screen" loading=lazy src=https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexPlayground/pyregex_examples.png></p><br><h2 id=brief-guide>Brief Guide<a aria-label="Anchor link for: brief-guide" class=zola-anchor href=#brief-guide>🔗</a></h2><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>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&LT0>)', ip)</code> will add parenthesis around the matching portions.<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.<blockquote><p><img alt=warning src=/images/warning.svg> There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.</blockquote><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>For more detailed instructions, see <a href=https://github.com/learnbyexample/TUI-apps/blob/main/PyRegexPlayground/app_guide.md>app guide</a>.</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/playground/>#playground</a><a href=https://learnbyexample.github.io/tags/tui/>#TUI</a><a href=https://learnbyexample.github.io/tags/textual/>#textual</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/understanding-python-regex-announcement/>Understanding Python re(gex)? book announcement →</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>
11+
</span></code></pre><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>Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines). Here's another screenshot:<p align=center><img alt="Sample screenshot from the Interactive Examples screen" loading=lazy src=https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/PyRegexPlayground/pyregex_examples.png></p><br><h2 id=brief-guide>Brief Guide<a aria-label="Anchor link for: brief-guide" class=zola-anchor href=#brief-guide>🔗</a></h2><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>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&LT0>)', ip)</code> will add parenthesis around the matching portions.<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.<blockquote><p><img alt=warning src=/images/warning.svg> There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.</blockquote><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>For more detailed instructions, see <a href=https://github.com/learnbyexample/TUI-apps/blob/main/PyRegexPlayground/app_guide.md>app guide</a>.</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/playground/>#playground</a><a href=https://learnbyexample.github.io/tags/tui/>#TUI</a><a href=https://learnbyexample.github.io/tags/textual/>#textual</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=previous href=https://learnbyexample.github.io/interactive-python-regex-exercises/>← 100+ Interactive Python Regex Exercises</a><br><p><a class=next href=https://learnbyexample.github.io/understanding-python-regex-announcement/>Understanding Python re(gex)? book announcement →</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>

‎sitemap.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<loc>https://learnbyexample.github.io/interactive-linux-cli-exercises/</loc>
6767
<lastmod>2023-03-15</lastmod>
6868
</url>
69+
<url>
70+
<loc>https://learnbyexample.github.io/interactive-python-regex-exercises/</loc>
71+
<lastmod>2023-03-20</lastmod>
72+
</url>
6973
<url>
7074
<loc>https://learnbyexample.github.io/javascript-regexp-cheatsheet/</loc>
7175
<lastmod>2023-02-09</lastmod>
@@ -164,7 +168,7 @@
164168
</url>
165169
<url>
166170
<loc>https://learnbyexample.github.io/python-25-days-of-regex/</loc>
167-
<lastmod>2022-12-09</lastmod>
171+
<lastmod>2023-03-20</lastmod>
168172
</url>
169173
<url>
170174
<loc>https://learnbyexample.github.io/python-for-maths/</loc>

‎tags/exercises/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!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>learnbyexample</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=learnbyexample property=og:title><meta content=website property=og:type><meta content="Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets." property=og:description><meta content=https://learnbyexample.github.io property=og:url><meta content=https://learnbyexample.github.io/images/learnbyexample.png property=og:image><meta content=1280 property=og:image:width><meta content=640 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=taxonomy><h2>exercises</h2><div class=taxonomy__item><span class=taxonomy__item__time>2022-12-09</span><span class=taxonomy__item__title> <a href=https://learnbyexample.github.io/interactive-linux-cli-exercises/>Interactive Linux CLI Text Processing Exercises</a> </span></div><div class=taxonomy__item><span class=taxonomy__item__time>2021-12-01</span><span class=taxonomy__item__title> <a href=https://learnbyexample.github.io/python-25-days-of-regex/>Improve your Python regex skills with 75 interactive exercises</a> </span></div></div></div></main></div><script src=https://learnbyexample.github.io/even.js></script>
1+
<!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>learnbyexample</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=learnbyexample property=og:title><meta content=website property=og:type><meta content="Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets." property=og:description><meta content=https://learnbyexample.github.io property=og:url><meta content=https://learnbyexample.github.io/images/learnbyexample.png property=og:image><meta content=1280 property=og:image:width><meta content=640 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=taxonomy><h2>exercises</h2><div class=taxonomy__item><span class=taxonomy__item__time>2023-03-20</span><span class=taxonomy__item__title> <a href=https://learnbyexample.github.io/interactive-python-regex-exercises/>100+ Interactive Python Regex Exercises</a> </span></div><div class=taxonomy__item><span class=taxonomy__item__time>2022-12-09</span><span class=taxonomy__item__title> <a href=https://learnbyexample.github.io/interactive-linux-cli-exercises/>Interactive Linux CLI Text Processing Exercises</a> </span></div><div class=taxonomy__item><span class=taxonomy__item__time>2021-12-01</span><span class=taxonomy__item__title> <a href=https://learnbyexample.github.io/python-25-days-of-regex/>Improve your Python regex skills with 75 interactive exercises</a> </span></div></div></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

‎tags/index.html

+1-1
Large diffs are not rendered by default.

‎tags/python/index.html

+1-1
Large diffs are not rendered by default.

‎tags/regular-expressions/index.html

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.