python re.findall ()

import re   # #导入模块re
"""
    re.findall(pattern, string, flags=0)
    查找字符串中所有(非重复)出现的正则表达式模式,并返回一个匹配列表
"""
str1='abcdefg';

print(re.findall('b.',str1))   #['bc']
print(re.findall('b(.)',str1))  #['c']
print(re.findall('b_',str1))   # []

print(re.findall('b',str1))   # ['b']

str2='ababbabbbcd'
print(re.findall('ab?',str2))   # ['ab', 'ab', 'ab']


str3='好雨知时节当春乃发生随风潜入夜润物细无声'
print(re.findall('风(.*?)春',str3))   # []

 

posted @ 2022-03-18 11:26  大熊童鞋  阅读(188)  评论(0编辑  收藏  举报