Discuss / Python / 我的解答

我的解答

Topic source

lubang03

#1 Created at ... [Delete] [Delete and Lock User]

第一题

import re

regStr = r'(\w.\w)@(\w.\w*)' pattern = re.compile(regStr)

m = pattern.match('someone@gmail.com') m1 = pattern.match('bill.gates@microsoft.com') print(m.groups()) print(m1.groups())

如果要划分groups的话,不加括号分割,得到的groups是空的tuple.

第二题

import re

regStr = r'<(\w\s{1}\w)>\s{1}(\w@\w.\w*)'

pattern = re.compile(regStr)

print(pattern.match('<Tom Paris> tom@voyager.org').groups())

hong泽智

#2 Created at ... [Delete] [Delete and Lock User]


  • 1

Reply