无法匹配正则表达式模式

2024-09-29 19:27:38 发布

您现在位置:Python中文网/ 问答频道 /正文

假设您有以下文本:

yada yada 
yada yada 1
;


<Hello.There>yada:EGHKJHKG, Source:QWEKGHGHJGKGHJKGHJKVMVNMVMVMVMVMVMVMBTDFHG, </Hello.There>
yada2
yada3

我只想在Source:之后和,之前获取信息。你知道吗

我已经用这个site完成了,并且匹配了源代码值 我的正则表达式是:
<Hello.There>.+Source:(.+?),\s*</Hello.There>

我的python代码是:

match = re.match(r'<Hello.There>.+Source:(.+?),\s*</Hello.There>
在这一行之后我一个也没有,有什么想法吗?
(我尝试了更多的regex选项,但没有成功)


Tags: 代码文本resourcehello源代码matchsite
1条回答
网友
1楼 · 发布于 2024-09-29 19:27:38

re.match只在字符串的开头匹配。如果不想只在开头匹配,就需要使用re.search。你知道吗

>>> import re
>>> re.match('llo', 'hello')   # only match at the beginning
>>> re.search('llo', 'hello')  # match anywhere
<_sre.SRE_Match object at 0x00000000029BA4A8>

search() vs. match() from the Python ^{} module documentation。你知道吗

相关问题 更多 >

    热门问题