In [7]: content = "<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"
In [8]: re.findall(r'<p>(.+?)</p>', content)
Out[8]:
["I'd like to find the string between the two paragraph tags.",
'And also this string']
import re
matches = re.findall(r'<p>.+?</p>',string)
下面是您在控制台中运行的文本。
>>>import re
>>>string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
>>>re.findall('<p>.+?</p>',string)
["<p>I'd like to find the string between the two paragraph tags.</p>", '<p>And also this string</p>']
import re
string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
subStr = re.findall(r'<p>(.+?)</p>',string)
print subStr
结果
["I'd like to find the string between the two paragraph tags.", 'And also this string']
3条答案
按热度按时间cunj1qz11#
介于
<p>
和</p>
之间bhmjp9jg2#
Regular expressions
下面是您在控制台中运行的文本。
vq8itlhq3#
如果您希望字符串位于p标记之间(不包括p标记),则在findall方法中向**.+?**添加括号
结果