Getting a unknown word out of a list with no spaces

Alexandr N Zamaraev tonal at promsoft.ru
Thu Jul 17 03:42:17 EDT 2008


Alexnb wrote:
>>>>> s = '--a href="/browse/brick"--brick--/a--'
>>>>> s
>> '--a href="/browse/brick"--brick--/a--'
>>>>> ''.join('<%s>' % l if i % 2 == 1 else l for i, l in 
>> enumerate(s.split('--')))
>> ' /browse/brick brick '
> 
> I'm sorry, I don't think I was being clear. I replaced the <'s with -- so it
> would post online w/o actually making a link. I just need to know how to get
> the "brick" out.
1) if string really '--a href="/browse/brick"--brick--/a--'
 >>> s.split('--', 3)[2]
brick
2) if string '<a href="/browse/brick">brick</a>'
 >>> s.split('>', 1)[1].split('<')[0]
brick



More information about the Python-list mailing list