python正则表达式百分号

2024-04-24 09:27:35 发布

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

我想从文本中提取包含“~~帐户(ed或s)~~~~~ sale(s)”的所有部分。我在用python!在

例如

sentence = "Henry Schenin inc, accounted for approximately 11% of our net sale"

我的正则表达式

^{pr2}$

然而,这

rx1.search(sentence)

只返回None

如果我用正则表达式

rx2 = re.compile('(.|\W){1,100}account(.|\W){1,100}for\W(.|\W){1,200}', re.I)

我得到了

<_sre.SRE_Match object; span=(0, 67), match='Henry Schenin inc, accounted for approximately 11>

有人能帮助我理解为什么这个正则表达式不能捕获百分号(%)后面的部分吗?在

{\I{I'want to start of the regular expressions.{I'want to start of the regular expressions.{I'want to start of the regular expressions。在


Tags: ofthetoforsalestartsentenceexpressions