How to match a hard space

Padraig Brady Padraig at Linux.ie
Thu Oct 3 07:11:26 EDT 2002


A wrote:
> Hi,
> I need to replace in a string several spaces by one space only for example
> from  text
> 
> """      
> (image)     Country    From
>        Loading region"""
> 
> I need to get
>  """(image) Country From Loading region"""
> 
> I use the following code
> 
> import re
> text="""      (image)     Country    From
>        Loading region"""
> 
> p = re.compile('\s+')
> vy=p.sub(' ',text)
> print vy
> 
> It works well only if there is a normal space( \x20 value) but if there is a hard space( 
> \x20\xA0) it does not work.
> Can you please help?
> Thanks 
> Ladislav

import re
string="te \xA0st"
re.sub('[ \t\xA0]+',' ',string)

Pádraig.

p.s. I'm wondering why there is no regular expression news group




More information about the Python-list mailing list