Skip to content

Commit e24a73f

Browse files
author
Mark Pilgrim
committed
be more precise about (a|b|c)
1 parent 86b4287 commit e24a73f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

regular-expressions.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ <h3 id=tensandones>Checking For Tens And Ones</h3>
221221
<li>This matches the start of the string, then the first optional <code>M</code>, then <code>CM</code>, then the optional <code>L</code> and all three optional <code>X</code> characters, then the end of the string. <code>MCMLXXX</code> is the Roman numeral representation of <code>1980</code>.
222222
<li>This matches the start of the string, then the first optional <code>M</code>, then <code>CM</code>, then the optional <code>L</code> and all three optional <code>X</code> characters, then <em>fails to match</em> the end of the string because there is still one more <code>X</code> unaccounted for. So the entire pattern fails to match, and returns <code>None</code>. <code>MCMLXXXX</code> is not a valid Roman numeral.
223223
</ol>
224-
<aside>(A|B) matches either pattern A or pattern B.</aside>
224+
<aside>(A|B) matches either pattern A or pattern B, but not both.</aside>
225225
<p>The expression for the ones place follows the same pattern. I&#8217;ll spare you the details and show you the end result.
226226
<pre class='nd screen'>
227227
<samp class=p>>>> </samp><kbd class=pp>pattern = '^M?M?M?(CM|CD|D?C?C?C?)(XC|XL|L?X?X?X?)(IX|IV|V?I?I?I?)$'</kbd>
@@ -431,7 +431,7 @@ <h2 id=summary>Summary</h2>
431431
<li><code>x*</code> matches <code>x</code> zero or more times.
432432
<li><code>x+</code> matches <code>x</code> one or more times.
433433
<li><code>x{n,m}</code> matches an <code>x</code> character at least <code>n</code> times, but not more than <code>m</code> times.
434-
<li><code>(a|b|c)</code> matches either <code>a</code> or <code>b</code> or <code>c</code>.
434+
<li><code>(a|b|c)</code> matches exactly one of <code>a</code>, <code>b</code> or <code>c</code>.
435435
<li><code>(x)</code> in general is a <em>remembered group</em>. You can get the value of what matched by using the <code>groups()</code> method of the object returned by <code>re.search</code>.
436436
</ul>
437437
<p>Regular expressions are extremely powerful, but they are not the correct solution for every problem. You should learn enough about them to know when they are appropriate, when they will solve your problems, and when they will cause more problems than they solve.

0 commit comments

Comments
 (0)