Handling Numbers Without Separators : search « Regular Expressions « Python Tutorial






import re 
phonePattern = re.compile(r'^(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)$')  
print phonePattern.search('00088812341234').groups()                     
print phonePattern.search('000.888.1234 x1234').groups()                
print phonePattern.search('000-888-1234').groups()                        
print phonePattern.search('(000)8881234 x1234')








16.5.search
16.5.1.Finding Numbers
16.5.2.Finding the Extension
16.5.3.Handling Different Separators
16.5.4.Handling Numbers Without Separators
16.5.5.Handling Leading Characters
16.5.6.Phone Number, Wherever I May Find Ye
16.5.7.Simple regular-expression example.