How to find the first space?

Diez B. Roggisch deets at nospam.web.de
Mon Jun 9 17:36:25 CEST 2008


Johny wrote:

> How can I find the first space using regex?
> 
> For example I have text
> Text=' This is a sample '
> 
> The last space I can remove by
> Text=re.sub(r"\s(?!\w)",'',Text)
> 
> but I do not know how to remove the first space.
> Can anyone help?

Use the strip-method, as defined on stringlike objects.

Diez



More information about the Python-list mailing list