Discuss / Python / 作业

作业

Topic source

Eliefly

#1 Created at ... [Delete] [Delete and Lock User]
>>> import re
>>> re_mailName = re.compile('^([a-zA-Z_.]+)\@(\w*)(.com)$')
>>> re_mailName.match('someone@gmail.com').groups()
('someone', 'gmail', '.com')
>>> re_mailName.match('bill.gates@microsoft.com').groups()
('bill.gates', 'microsoft', '.com')
>>> 
>>> re_mailName2 = re.compile('^(<[a-zA-Z_.\s]+>)(\w*)\@(\w*)(.org)$')
>>> re_mailName2.match('<Tom Paris>tom@voyager.org').groups()
('<Tom Paris>', 'tom', 'voyager', '.org')
>>> re_mailName2.match('<Tom Paris>tom@voyager.org').group(2)
'tom'

  • 1

Reply