-
^
^表示字符串的开头,^+86表示字符串的开头必须是+86 -
$
$表示字符串结尾,+86$表示字符串结尾必须是+86
使用案例
import re
regex = r'^\+86$'
text = '+86'
matchObj = re.search(regex, text)
if matchObj:
print(text + ' 是中国区号')
else:
print(text + " 不是中国区号")
^
^表示字符串的开头,^+86表示字符串的开头必须是+86
$
$表示字符串结尾,+86$表示字符串结尾必须是+86
使用案例
import re
regex = r'^\+86$'
text = '+86'
matchObj = re.search(regex, text)
if matchObj:
print(text + ' 是中国区号')
else:
print(text + " 不是中国区号")