On 06/08/15 06:39, Aadesh Shrestha wrote:
import re
text = input('Enter your text with phone number using xx-xxxxxxx format \n')
contact = re.compile(r'\d\d-\d\d\d\d\d\d\d')
for i in range(len(text)):
chunk = text[i:i+10]
mo = contact.search(chunk)
if mo:
print('Phone Number Found:'+mo.group())
Remove the loop?
re.search can find the pattern in the whole of text
without a loop. That's basically the point of it.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor