Python 可供重新选择的多个选项

Python 可供重新选择的多个选项,python,regex,Python,Regex,我试图使用re从这个句子中提取单词“single report”,但它也返回“”值 请帮忙 下面是一个例子: import re txt = "they were looking for a single report not an ongoing service access to our products and therefore our solution was irrelevant for them currently even though the subscription woul

我试图使用re从这个句子中提取单词“single report”,但它也返回“”值 请帮忙 下面是一个例子:

import re
txt = "they were looking for a single report not an ongoing service access to our products and therefore our solution was irrelevant for them currently even though the subscription would include what they were looking for this would not be an arr deal and did not match what they were looking to pay for a one off report and therefore they were not interested in moving forward "
x = re.findall(r'one report|1 report|single report|', txt)
print(x)
结果是:

['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'single report', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']

如何在不更改同时获取“一份报告”或“一份报告”的选项的情况下删除所有“”?

最后一个
|
不匹配任何字符,请删除它:

x = re.findall(r'one report|1 report|single report', txt)
感谢@JvdV指出另一个很好的方法:

x = re.findall(r'(?:one|1|single) report', txt)

最后一个
|
不匹配任何字符,请将其删除:

x = re.findall(r'one report|1 report|single report', txt)
感谢@JvdV指出另一个很好的方法:

x = re.findall(r'(?:one|1|single) report', txt)

试着移除尾随的垂直巴里,我认为你不希望最后一个
|
出现在图案的末尾。这与一个空的空格相匹配。尝试删除尾随的垂直barI。我认为您不希望最后一个
位于图案的末尾。这与一个空空间相匹配。Upvoted=)。也许只是一个建议,但OP似乎使用了
report
repetitive。因此,另一种方法是:
x=re.findall(r'(?:一个| 1 |单个)报告',txt)
带有非捕获组=)向上投票=)。也许只是一个建议,但OP似乎使用了
report
repetitive。因此,另一种方法是:
x=re.findall(r'(?:一个| 1 |单个)报告',txt)
和一个非捕获组=)