-1

I have a string something similar to this.

str1=r'<st-button mode="positive" width="small" can-click="{loadConference}" id="meetingPasswordButton">{{i18n "ok"}}</st-button>'

I want to include everything between < and > and reject everything between </ and >.

I tried this to include and reject the text between those special characters using following code. But I am unable to get the output. Help me cracking this situation.

code:

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 Answers2

0

Following regular expression will return the data between < and >:

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

Output:

['st-button mode="positive" width="small" can-click="{loadConference}"id="meetingPasswordButton"']
niemmi
  • 17,113
  • 7
  • 35
  • 42
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"']
Pagefault
  • 339
  • 1
  • 12