Python 匹配所有定期事件

Python 匹配所有定期事件,python,regex,Python,Regex,我想提取Python中所有出现的模式。 这就是我所做的 import re string="Any information <p>sent to the server as clear text</p>, may be stolen and used later for <p>identity theft</p> or user impersonation. In addition, several privacy regulations sta

我想提取Python中所有出现的模式。 这就是我所做的

import re

string="Any information <p>sent to the server as clear text</p>, may be stolen and used later for <p>identity theft</p> or user impersonation. In addition, several privacy regulations state that sensitive information such as user<p> credentials will always be sent encrypted </p> to the web site."

regex='<p>.*</p>' # obviously it matches starting <p> to the last </p>

if re.findall(regex, String):
    print(re.findall(regex, string))
else:
    print('no match found')
重新导入
string=“以明文形式发送到服务器的任何信息都可能被窃取,并在以后用于身份盗窃或用户模拟。此外,一些隐私法规规定,敏感信息(如用户凭据)将始终加密发送到网站。”
正则表达式=“*

”#显然它匹配从开始到最后一个

如果关于findall(正则表达式,字符串): 打印(关于findall(正则表达式,字符串)) 其他: 打印('未找到匹配项')
我想提取所有段落标记的出现。我的意思是输出应该是一个如下所示的列表

['<p>sent to the server as clear text</p>', '<p>identity theft</p>', '<p> credentials will always be sent encrypted </p>']
['以明文形式发送到服务器,'身份盗窃

,'凭据将始终加密发送

']
我发现了一些类似的问题,但没有达到目的


更改您的
regex
如下:

regex=r"<p>.*?</p>"
regex=r“*?

它给出的o/p类似于:

['<p>sent to the server as clear text</p>', '<p>identity theft</p>', 
 '<p> credentials will always be sent encrypted </p>']
[”以明文形式发送到服务器,“身份盗窃”

, “凭据将始终加密发送”

“]
第一个故障源通常是正则表达式,您可以在此处检查它,不要使用
re.findall
两次。使用
res=re.findall(…)
,然后在检查
res
length后显示所需的消息。在这里获得答案。*非贪婪完成了这一技巧。。谢谢@WiktorStribiżewt这正是正则表达式。正则表达式='*?'