a regual expression problem

Jon Clements joncle at googlemail.com
Sun Nov 30 05:44:27 EST 2008


On Nov 30, 9:10 am, lookon <areyouloo... at gmail.com> wrote:
> I have a url of image, and I want to get the filename and extension of
> the image. How to write in python?
>
> for example, the url ishttp://a.b.com/aaa.jpg?version=1.1
>
> how can I get aaa and jpg by python?

Something like...

>>> from urlparse import urlsplit
>>> from os.path import splitext
>>> splitext(urlsplit('http://a.b.com/aaa.jpg?version=1.1').path[1:])
('aaa', '.jpg')

...and then it should be fairly flexible instead of having to change
splitting etc..

hth

Jon.



More information about the Python-list mailing list