正規表現05-先頭と末尾の一致
1156 ワード
先頭と末尾の一致
文字
機能
^
一致文字列の先頭
$
一致文字列の末尾
例1:$
需要:一致163.comのメールアドレス
実行結果:
完備後
実行結果:
文字
機能
^
一致文字列の先頭
$
一致文字列の末尾
例1:$
需要:一致163.comのメールアドレス
#coding=utf-8
import re
email_list = ["[email protected]", "[email protected]", "[email protected]"]
for email in email_list:
ret = re.match("[\w]{4,20}@163\.com", email)
if ret:
print("%s , :%s" % (email, ret.group()))
else:
print("%s " % email)
実行結果:
[email protected] , :[email protected]
[email protected] , :[email protected]
[email protected]
完備後
email_list = ["[email protected]", "[email protected]", "[email protected]"]
for email in email_list:
ret = re.match("[\w]{4,20}@163\.com$", email)
if ret:
print("%s , :%s" % (email, ret.group()))
else:
print("%s " % email)
実行結果:
[email protected] , :[email protected]
[email protected]
[email protected]