line = "booobooobbbaby123"
import re
regex_str = ".*(b.*b).*"
print(re.match(regex_str,line).group(1))
输出:bab
慕课网解释满足圆括号的字符串应从源字符串右往左匹配,加上?变为非贪婪模式后从左往右
line = "booobooobbbaby123"
import re
regex_str = ".*?(b.*b).*"
print(re.match(regex_str,line).group(1))
输出:booobooobbbab
line = "booobooobbbaby123"
import re
regex_str = ".*?(b.*?b).*"
print(re.match(regex_str,line).group(1))
输出:booob