首页 > 解决方案 > Python regex - 在 regex101.com 中使用 re.findall() v/s clean 组进行零长度匹配

问题描述

为什么我在使用时得到零长度匹配,re.findall()而在评估 regex101 上的模式时却没有得到任何匹配:

text:
Relatie                    f. dsgfsdg\n 
Factuur                    26427432\n
Machtiging                 436346y435643yerhg\n
IncassantID                4ty43y643erhgerh\n
Onderwerp                  Uw factuur\n
Datum                      25 mei 2014\n

本地(jupyter 笔记本):

re.findall('(Factuur)(\s+)(\d+)|(Datum)(\s+)(\d+\s+\w+\s+\d+)', content)
[('Factuur', '                    ', '2423828', '', '', ''),
 ('', '', '', 'Datum', '                      ', '25 mei 2014')]

正则表达式101.com:

r"(Factuur)(\s+)(\d+)|(Datum)(\s+)(\d+\s+\w+\s+\d+)"

在此处输入图像描述

标签: pythonregex

解决方案


推荐阅读