From 317fc05812fafd5f01cd755ecaab185ea6afdb44 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Mon, 2 Aug 2010 14:25:26 -0400 Subject: [PATCH] spacing fiddling --- regular-expressions.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regular-expressions.html b/regular-expressions.html index 5a75a44..b3f26d8 100755 --- a/regular-expressions.html +++ b/regular-expressions.html @@ -384,9 +384,9 @@ AttributeError: 'NoneType' object has no attribute 'groups' >>> phonePattern = re.compile(r'(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)$') >>> phonePattern.search('work 1-(800) 555.1212 #1234').groups() ('800', '555', '1212', '1234') ->>> phonePattern.search('800-555-1212').groups() +>>> phonePattern.search('800-555-1212').groups() ('800', '555', '1212', '') ->>> phonePattern.search('80055512121234').groups() +>>> phonePattern.search('80055512121234').groups() ('800', '555', '1212', '1234')
  1. Note the lack of ^ in this regular expression. You are not matching the beginning of the string anymore. There’s nothing that says you need to match the entire input with your regular expression. The regular expression engine will do the hard work of figuring out where the input string starts to match, and go from there.