![](/img/trans.png)
[英]Python Regular Expression to combine outer text with text between tags
[英]Regular expression in python to split each text between tags
這是我的字符串"<p>First</p><p>Second</p><p>Third</p>"
我想將 First、Second 和 Third 放入列表中。 那么有沒有辦法在 python 中做到這一點?
您可以使用re.findall
:
import re
s = "<p>First</p><p>Second</p><p>Third</p>"
re.findall(r"<p>(.*?)</p>", s)
# ['First', 'Second', 'Third']
括號(...)
標記捕獲的組(如果存在,則由 findall 使用)和?
非貪婪地匹配,這樣你就不會從第一個開始到最后一個結束標簽只得到一個匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.