[Tutor] How can this code be made even better ?

Aadesh Shrestha aadeshere1 at gmail.com
Thu Aug 6 07:39:21 CEST 2015


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())


Thanks

************************
Aadesh Shrestha


More information about the Tutor mailing list