Discuss / Python / 练习1:需要注意.匹配任意字符,需要转义'\.'

练习1:需要注意.匹配任意字符,需要转义'\.'

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
import redef is_valid_email(addr):    re_mail = re.compile(r'^(\w+)((\.\w+)?)@(\w+)(.com)$')    if re_mail.match(addr):        return True    else:        return Falseassert is_valid_email('someone@gmail.com')assert is_valid_email('bill.gates@miscrosoft.com')assert not is_valid_email('bob#examole.com')assert not is_valid_email('mr-bob@exceple.com')print('ok')

  • 1

Reply