Trouble splitting strings with consecutive delimiters

Temia Eszteri lamialily at cleverpun.com
Tue May 1 13:13:55 EDT 2012


>> re.split(':|;|px', "width:150px;height:50px;float:right")
>
>You could recognize that the delimiter you want to strip is in fact px; 
>and not px in and of itself.
>
>So, try:
>
>re.split(':|px;', "width:150px;height:50px;float:right")
>
>Emile

That won't work at all outside of the example case. It'd choke on any
attribute seperator that didn't end in px.

Honestly I'd recommend recovering the size measurement anyway, since
there are pretty huge differences between each form of measurement in
CSS. Seperating it from the number itself is fine and all since you
probably still need to turn it into a number Python can use, but I
wouldn't discard it outright.

~Temia
--
When on earth, do as the earthlings do.



More information about the Python-list mailing list