regex, split and ()
Jacek Popławski
jp at ulgo.koti.com.pl
Wed Dec 27 12:14:34 EST 2000
I think I understand how regex split works:
>>> d=re.compile(r'(aa)')
>>> a="bbaacceeaadd"
>>> d.split(a)
['bb', 'aa', 'ccee', 'aa', 'dd']
I want to use this regex:
<[^<>]*(".*")?>
so:
>>> w=re.compile(r'(<[^<>]*(".*")?>)')
>>> s="<html> one <br> two <img src=\"<blah\"> three </html>"
>>> w.split(s)
['', '<html>', None, ' one ', '<br>', None, ' two ', '<img src="<blah">',
'"<blah"', ' three ', '</html>', None, '']
works good, but why it double everything? probably becouse I used second (),
how to fix it?
--
Changes comes slowly
But this is what you'll be
Somehow it snows in the summer
And the sun is freezing me "Otherworld" - Ronnie James Dio
More information about the Python-list
mailing list