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

> AttributeError: 'NoneType' object has no attribute 'group'

When match doesn't find anything it returns None, which has no 
group() method.

Why does it not find the regex?
Because you used match() which looks for a match starting 
at the beginning of the line. You need to use search() 
instead...

I discuss this in my tutorial topic on regex...

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to