[Tutor] error message

Kent Johnson kent37 at tds.net
Mon Feb 14 03:12:44 CET 2005


Jacob S. wrote:
> Dive into Python, an excellent tutorial has a case study on this very 
> same topic.
> 
> The biggest problem that nobody has mentioned yet is the fact that 
> group() will not have anything unless you explicitly tell it to group it.

group() defaults to returning group 0 which is the whole match.

  >>> import re
  >>> string = 'My phone is 410-995-1155'
  >>> pattern = r'\d{3}-\d{3}-\d{4}'
  >>> re.search(pattern,string).group()
'410-995-1155'

Kent



More information about the Tutor mailing list