首页 > 文章列表 > python正则表达式问号的使用

python正则表达式问号的使用

Python 正则表达式
314 2022-08-07

1、声明与非贪心的匹配。

2、表示可选的分组。用星号匹配零次或多次、一次或多次用加号匹配、用花括号匹配特定次数、贪婪与非贪婪的匹配。

实例

import re
 
a = 'wxxIxxeuieiejfsdjxxlovexxfsiewiweirxxUxxwuerowiur'
b = re.findall('xx(.*?)xx', a)
print(b)
print(type(b))
 
for item in b:
print(item)

输出

['I', 'love', 'U']
<class 'list'>
I
love
U

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。