I have a string which has defined tags around specific words or sub-strings. For example:
text = 'Bring me to <xxx>ibis and the</xxx> in <ccc>NW</ccc> and the <sss>Jan</sss>
<hhh>10</hhh>'
How can I get the strings <xxx>ibis and the</xxx>
, <ccc>NW</ccc>
, <sss>Jan</sss>
and <hhh>10</hhh>
. These tags can be anything but the tags covering a word or few words will be similar. Also, if a start or end tag is missing, I don't want that string to be returned. For example:
text = 'Bring me to <xxx>ibis and the in NW</ccc> and the <sss>Jan</sss>
<hhh>10</hhh>'
In this case, only <sss>Jan</sss>
and <hhh>10</hhh>
has to be returned.