我在Python 3脚本中遇到了正则表达式的问题:
变量具有以下内容:
<p class="paragraphClass" id="firstParagraph"><span class="spanClass" id="firstSpan">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam faucibus massa et justo aliquam consequat.</span></p><p class="paragraphClass" id="secondParagraph"><span class="spanClass" id="secondSpan">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam faucibus massa et justo aliquam consequat.</span></p><p class="paragraphClass" id="thirdParagraph"><span class="spanClass">##START_ACT##</span></p><p class="paragraphClass" id="firstParagraph"><span class="spanClass" id="firstSpan">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam faucibus massa et justo aliquam consequat.</span></p>
我想得到:
<p class="paragraphClass" id="thirdParagraph"><span class="spanClass">##START_ACT##</span></p>
但我必须搜索字符串##START_ACT##
我不知道其他字符串的长度,类或id的名称,所以我不能相信正则表达式,例如:
<p.{0,80}##START_ACT##.*?</p>
这可以用正则表达式完成吗?
答案 0 :(得分:0)
试试这个正则表达式:
r".*(<p.*?##START_ACT##.*?/p>).*"
它将匹配整个文本,但该组将仅包含您需要的内容。