mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
fix overzealous global replace
This commit is contained in:
@@ -282,7 +282,7 @@ body{counter-reset:h1 5}
|
||||
<p class=a>⁂
|
||||
|
||||
<h2 id=phonenumbers>Case study: Parsing Phone Numbers</h2>
|
||||
<aside>\d matches any numeric digit (0–10). \D matches anything but digits.</aside>
|
||||
<aside>\d matches any numeric digit (0–9). \D matches anything but digits.</aside>
|
||||
<p>So far you’ve concentrated on matching whole patterns. Either the pattern matches, or it doesn’t. But regular expressions are much more powerful than that. When a regular expression <em>does</em> match, you can pick out specific pieces of it. You can find out what matched where.
|
||||
<p>This example came from another real-world problem I encountered, again from a previous day job. The problem: parsing an American phone number. The client wanted to be able to enter the number free-form (in a single field), but then wanted to store the area code, trunk, number, and optionally an extension separately in the company’s database. I scoured the Web and found many examples of regular expressions that purported to do this, but none of them were permissive enough.
|
||||
<p>Here are the phone numbers I needed to be able to accept:
|
||||
|
||||
Reference in New Issue
Block a user