2016-03-21 9 views
-1

これに類似した文字列があります。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)) 
+2

読む[この](HTTP: //stackoverflow.com/a/1732454/ 2276527) – Gogo

答えて

0

次の正規表現:

print(re.findall('<((?!/).*?)>', s)) 

出力:

['st-button mode="positive" width="small" can-click="{loadConference}"id="meetingPasswordButton"'] 
+0

ありがとう:) –

0
>>> import re 
>>> s = r'<st-button mode="positive" width="small" can-click="{loadConference}" id="meetingPasswordButton">{{i18n "ok"}}</st-button>' 
>>> print re.findall(r'<([^\/].*?)>', s) 
['st-button mode="positive" width="small" can-click="{loadConference}" id="meetingPasswordButton"'] 
関連する問題