关于用法:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143193331387014ccd1040c814dee8b2164bb4f064cff000#0
廖大已经解释的很详细了。
一个小小的demo,检验email格式的问题:
import re def check_email(object): # re_email=re.compile(r'[0-9a-zA-Z\_]*@[a-z]*.[a-z]{0,9}') if re.match(r'(^[0-9a-zA-Z\_]*)@([a-z]+.)([a-zA-z]+)',object): print('ok') print(re.match(r'(^[0-9a-zA-Z\_]*?)@([0-9a-z]+.)(\w+)',object).groups()) else: print('failed') if __name__=="__main__": input_email='ylc123gg@qq.com' check_email(input_email)
输出:
ok
('ylc123gg', 'qq.', 'com')
Process finished with exit code 0
十分方便~