change a string conditional
Ewald van Houte
ehoute_zeelandnet_nl
Thu May 9 18:05:31 EDT 2002
"obantec support" <spam at nomail.net> wrote in
news:udlaulccmpa3f5 at news.supernews.com:
> Hi
>
> I need to a piece of python code that will take a string which may or
> may not begin with www and change it to lists.
>
> eg. www.domain.com becomes lists.domain.com
> but if domain1.com (no www) the it still becomes lists.domain1.com
>
> an example of a pattern match will be enough.(I do a bit of perl but
> never done any python)
>
> mark
>
>
>
import re
def f(url):
return 'lists.' + re.sub('^www.\.','',url)
Testing it:
>>> f('domain1.com')
'lists.domain1.com'
>>> f('www.domain.com')
'lists.domain.com'
Maybe better pattern possible, but too lazy now :p
HTH,
Ewald
More information about the Python-list
mailing list