Lalit Chattar
Lalit Chattar

Reputation: 704

string operation

i have a string in which a word is like this "#<i><b>when</b></i>". i want only word without any tag. when in striped "#" word became "<i><b>when</b></i>". but when i striped "<i>" word became like "b>when"<b>when</b>"?

Upvotes: 0

Views: 117

Answers (2)

Zeke
Zeke

Reputation: 2042

Use regular expressions.

>>> import re
>>> s='#<i><b>when</b></i>'
>>> wordPattern = re.compile(r'\>(\w+)\<')
>>> wordPattern.search(s).groups()
('when',)

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

Slice it.

>>> '#<i><b>when</b></i>'[4:-4]
'<b>when</b>'

Upvotes: 1

Related Questions