📄 parsephone.py
字号:
"""Parse U.S. phone numbersThis program is part of "Dive Into Python", a free Python book forexperienced programmers. Visit http://diveintopython.org/ for thelatest version."""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.3 $"__date__ = "$Date: 2004/05/05 21:57:19 $"__copyright__ = "Copyright (c) 2002 Mark Pilgrim"__license__ = "Python"import reclass InvalidPhoneNumber(Exception): passphonePattern = re.compile(r""" ^ # match beginning of string \D* # swallow anything that isn't numeric 1? # swallow leading 1, if present \D* # swallow anything that isn't numeric (\d{3}) # capture 3-digit area code \D* # swallow anything that isn't numeric (\d{3}) # capture 3-digit trunk \D* # swallow anything that isn't numeric (\d{4}) # capture 4-digit number \D* # swallow anything that isn't numeric (\d*) # capture extension, if present """, re.VERBOSE)def parsePhoneNumber(phoneNumber): match = phonePattern.search(phoneNumber) if match: return match.groups() else: raise InvalidPhoneNumber, phoneNumber
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -