Finding Numbers : search « Regular Expressions « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Regular Expressions » search 
16.5.1.Finding Numbers
import re 
phonePattern = re.compile(r'^(\d{3})-(\d{3})-(\d{4})$')    
print phonePattern.search('000-888-1234').groups()             
print phonePattern.search('000-888-1234-1234')
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.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.