Python 正则表达式,边界匹配(search)

时间:2025-02-11 21:04:58

边界匹配:

import re

# \A 和 ^ 表示开头  ^可以处理多行  ^the是否以the开头
# \Z 和 $ 表示结尾  $可以处理多行  the$是否以the结尾
# \b 在search()中表示特殊字符(a-z A-Z 0-9之外的字符) 
# \b the\b  the的后面是否是特殊字符,结尾(结束标志)也表示特殊字符
# \B 在search()中表示字母或数字

m=(r"\Bthe\b","my 5the!")
if  m  is not None:
    print(())
else:
    print("not find")