我有一个类似于此的字符串。包含并忽略2个特殊字符之间的文本
str1=r'<st-button mode="positive" width="small" can-click="{loadConference}" id="meetingPasswordButton">{{i18n "ok"}}</st-button>'
我想包括<
和>
之间的一切,拒绝</
和>
之间的一切。
我试过用这些代码包含和拒绝这些特殊字符之间的文本。但我无法获得输出。帮助我解决这种情况。
代码:
import re
pat = r'(?<=\<).+?(?=\>)' or r'(?<!\</).+?(?!\>)'
s = r'<st-button mode="positive" width="small" can-click="{loadConference}" id="meetingPasswordButton">{{i18n "ok"}}</st-button>'
print (re.findall(pat, s))
阅读[此](HTTP: //stackoverflow.com/a/1732454/ 2276527) – Gogo