Skip to content

Commit e862afa

Browse files
committed
Add Regular Expressions Quick Reference to regex_inverter/index.html
1 parent 6fdbd88 commit e862afa

1 file changed

Lines changed: 57 additions & 14 deletions

File tree

‎examples/regex_inverter/index.html‎

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
.controls { margin-bottom: 1em; }
1414
table { border-collapse: collapse; width: 100%; }
1515
table th, table td { border: 1px solid #ddd; padding: 8px; text-align: left; }
16-
table th { background-color: #f2f2f2; }
16+
table th { background-color: #f2f2f2; text-align: center; }
17+
table.quick-ref td:first-child { text-align: center; }
1718
</style>
1819
</head>
1920
<body>
@@ -27,13 +28,55 @@ <h4>by Paul McGuire, January 2026</h4>
2728
<p><strong>Constraints:</strong></p>
2829
<ul>
2930
<li>Unbounded repetition operators <code>+</code> and <code>*</code> are <strong>not supported</strong>.</li>
30-
<li>Replace <code>+</code> or <code>*</code> with explicit <code>{n}</code> or <code>{min,max}</code> repetition operators (e.g., use an explicit repetition like <code>[A-Z]{1,4}</code> instead of <code>[A-Z]+</code>, or <code>[A-Z]{,4}</code> instead of <code>[A-Z]*</code>).</li>
31-
<li>For brevity, all generated strings in this utility are limited to 7-bit ASCII characters. By default, Python's re methods will match the full Unicode set, so macros like <code>\d</code> could match numeric digits in other language character sets beyond just the ASCII digits '0' through '9'.</li>
31+
<li>Replace <code>+</code> or <code>*</code> with explicit <code>{1,n}</code> or <code>{min,max}</code> repetition operators (e.g., use an explicit repetition like <code>[A-Z]{1,4}</code> instead of <code>[A-Z]+</code>, or <code>[A-Z]{,4}</code> instead of <code>[A-Z]*</code>).</li>
32+
<li>For brevity, all generated strings in this utility are limited to 7-bit ASCII characters. By default, Python's <code>re</code> methods will match the full Unicode set, so macros like <code>\d</code> could match numeric digits in other language character sets beyond just the ASCII digits '0' through '9'.</li>
3233
</ul>
3334
<p><strong>Note:</strong> Complex regular expressions or those with large repetition counts may take some time to process.</p>
3435
</div>
3536
</details>
3637
<p>
38+
<details>
39+
<summary>Regular Expressions Quick Reference</summary>
40+
<div>
41+
<table class="quick-ref">
42+
<thead>
43+
<tr><th>Construct</th><th>Description</th></tr>
44+
</thead>
45+
<tbody>
46+
<tr><td><code>.</code></td><td>Any character except newline</td></tr>
47+
<tr><td><code>\d</code></td><td>Digit <code>[0-9]</code></td></tr>
48+
<tr><td><code>\w</code></td><td>Word (identifier) character <code>[a-zA-Z0-9_]</code></td></tr>
49+
<tr><td><code>\s</code></td><td>Whitespace character</td></tr>
50+
<tr><td><code>\D</code></td><td>Non-digit</td></tr>
51+
<tr><td><code>\W</code></td><td>Non-word character</td></tr>
52+
<tr><td><code>\S</code></td><td>Non-whitespace character</td></tr>
53+
<tr><td><code>?</code></td><td>0 or 1 repetition</td></tr>
54+
<tr><td><code>{n}</code></td><td>Exactly <i>n</i> repetitions</td></tr>
55+
<tr><td><code>{n,m}</code></td><td>Between <i>n</i> and <i>m</i> repetitions</td></tr>
56+
<tr><td><code>{,m}</code></td><td>0 to <i>m</i> repetitions</td></tr>
57+
<tr><td><code>[...]</code></td><td>Character class (any of these characters)</td></tr>
58+
<tr><td><code>[^...]</code></td><td>Negated character class</td></tr>
59+
<tr><td><code>|</code></td><td>Alternation (OR)</td></tr>
60+
<tr><td><code>(...)</code></td><td>Grouping</td></tr>
61+
<tr><td><code>(?:...)</code></td><td>Grouping (non-capturing)</td></tr>
62+
<tr><td><code>(?P&lt;name&gt;...)</code></td><td>Grouping (named group)</td></tr>
63+
<tr><td colspan="2">Other common regex features not covered in this utility</td></tr>
64+
<tr><td><code>^</code></td><td>Start of a line</td></tr>
65+
<tr><td><code>$</code></td><td>End of a line</td></tr>
66+
<tr><td><code>\A</code></td><td>Start of string</td></tr>
67+
<tr><td><code>\Z</code></td><td>End of string</td></tr>
68+
<tr><td><code>*</code></td><td>0 or more repetitions (use <code>{,m}</code> to limit repetitions)</td></tr>
69+
<tr><td><code>+</code></td><td>1 or more repetitions (use <code>{1,m}</code> to limit repetitions)</td></tr>
70+
<tr><td><code>\b</code></td><td>Word boundary</td></tr>
71+
<tr><td><code>(?=...)</code></td><td>Positive lookahead</td></tr>
72+
<tr><td><code>(?!...)</code></td><td>Negative lookahead</td></tr>
73+
<tr><td><code>(?&lt;=...)</code></td><td>Positive lookbehind</td></tr>
74+
<tr><td><code>(?&lt;!...)</code></td><td>Negative lookbehind</td></tr>
75+
</tbody>
76+
</table>
77+
</div>
78+
</details>
79+
<p>
3780
<details>
3881
<summary>Examples</summary>
3982
<div>
@@ -44,43 +87,43 @@ <h4>by Paul McGuire, January 2026</h4>
4487
</thead>
4588
<tr>
4689
<td>Match one uppercase letter followed by three digits</td>
47-
<td><pre>[A-Z]-\d{3}</pre></td>
90+
<td><code>[A-Z]-\d{3}</code></td>
4891
</tr>
4992
<tr>
5093
<td>Time of day (HH:MM:SS)</td>
51-
<td><pre>(2[0-3]|[01]\d):([0-5]\d):([0-5]\d)</pre></td>
94+
<td><code>(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])</code></td>
5295
</tr>
5396
<tr>
5497
<td>8-bit binary numbers</td>
55-
<td><pre>[01]{8}</pre></td>
98+
<td><code>[01]{8}</code></td>
5699
</tr>
57100
<tr>
58101
<td>Integer from 0 to 99</td>
59-
<td><pre>[1-9]?\d</pre></td>
102+
<td><code>[1-9]?\d</code></td>
60103
</tr>
61104
<tr>
62105
<td>Integer from 0 to 255</td>
63-
<td><pre>25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d</pre></td>
106+
<td><code>25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d</code></td>
64107
</tr>
65108
<tr>
66109
<td>Roman Numerals to 50</td>
67-
<td><pre>(X{,3}|XL)(I{,3}|IV|VI{,3}|IX)|L</pre></td>
110+
<td><code>(X{,3}|XL)(I{,3}|IV|VI{,3}|IX)|L</code></td>
68111
</tr>
69112
<tr>
70113
<td>IPv4 addresses in 192.168.0.0/16</td>
71-
<td><pre>192\.168(\.((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d))){2}</pre></td>
114+
<td><code>192\.168(\.((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d))){2}</code></td>
72115
</tr>
73116
<tr>
74117
<td>MAC address</td>
75-
<td><pre>[0-9A-Fa-f]{2}([:-][0-9A-Fa-f]{2}){5}</pre></td>
118+
<td><code>[0-9A-Fa-f]{2}([:-][0-9A-Fa-f]{2}){5}</code></td>
76119
</tr>
77120
<tr>
78121
<td>UUID</td>
79-
<td><pre>[0-9A-F]{8}(-[0-9A-F]{4}){3}-[0-9A-F]{12}</pre></td>
122+
<td><code>[0-9A-F]{8}(-[0-9A-F]{4}){3}-[0-9A-F]{12}</code></td>
80123
</tr>
81124
<tr>
82-
<td>Original US Area codes</td>
83-
<td><pre>[2-9][10][2-9]</pre></td>
125+
<td>Original US Area codes (leading and trailing digit 2-9, middle digit 1 or 0)</td>
126+
<td><code>[2-9][10][2-9]</code></td>
84127
</tr>
85128
</table>
86129
</div>

0 commit comments

Comments
 (0)