当前位置:主页 > 软件编程 > Python代码 >

python 使用re.search()筛选后 选取部分结果的方法

时间:2021-02-04 11:36:40 | 栏目:Python代码 | 点击:

使用group()方法

b = 'hello good fine'
re.search(r'^hello\s(.*)\sfine',b).group()

python re.search()筛选后 选取部分结果

group() 会返回匹配此正则表达式的字符串

group(1) 会返回正则表达式中第一个括号内的内容, 以此类推,group(2) 第二个括号

re.search(r'^hello\s(.*)\sfine',b).group(1)

python re.search()筛选后 选取部分结果

* 如果需要筛选,则要在正则表达式里把 需要筛选的东西括上

python re.search()筛选后 选取部分结果

您可能感兴趣的文章:

相关文章