正则1
import re
line = "bobby123"
# 字符串以b开头,. 表示除换行的任意字符 *表个数
regex_str = "^b.*"
if re.match(regex_str,line):
print("matched")
# 字符串以$结尾
regex_str = ".*3$"
if re.match(regex_str,line):
print("matched")
# ?非贪婪模式,默认贪婪匹配(匹配满足要求的最大长度的字符串)
line = "bo00000000bbbbby123"
regex_str = ".*(b.*b).*"
match_obj = re.match(regex_str,line)
if match_obj:
print(match_obj.group(1)) # bb
# 思考:为什么结果是bb呢?反向开始 匹配的
regex_str = ".*?(b.*?b).*"
match_obj = re.match(regex_str,line)
if match_obj:
print(match_obj.group(1)) # bo00000000b