From 825254bdd690996091c42293ddb2df3a0268ca84 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 28 Jan 2010 14:26:37 -0500 Subject: [PATCH] fix overzealous global replace --- advanced-iterators.html | 2 +- regular-expressions.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced-iterators.html b/advanced-iterators.html index 483b98f..d012cc9 100755 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -36,7 +36,7 @@ S = 6 T = 2 E = 4 -

Puzzles like this are called cryptarithms or alphametics. The letters spell out actual words, but if you replace each letter with a digit from 0–10, it also “spells” an arithmetic equation. The trick is to figure out which letter maps to each digit. All the occurrences of each letter must map to the same digit, no digit can be repeated, and no “word” can start with the digit 0. +

Puzzles like this are called cryptarithms or alphametics. The letters spell out actual words, but if you replace each letter with a digit from 0–9, it also “spells” an arithmetic equation. The trick is to figure out which letter maps to each digit. All the occurrences of each letter must map to the same digit, no digit can be repeated, and no “word” can start with the digit 0.

diff --git a/regular-expressions.html b/regular-expressions.html index d18af91..edd23e9 100755 --- a/regular-expressions.html +++ b/regular-expressions.html @@ -282,7 +282,7 @@ body{counter-reset:h1 5}

Case study: Parsing Phone Numbers

- +

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 does match, you can pick out specific pieces of it. You can find out what matched where.

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.

Here are the phone numbers I needed to be able to accept: