How to find the first space?

Diez B. Roggisch deets at nospam.web.de
Mon Jun 9 11:35:52 EDT 2008


Russell Blau wrote:

> "Johny" <python at hope.cz> wrote in message
> news:7a91cc8f-2e93-46e9-8360-a01da9170187 at m44g2000hsc.googlegroups.com...
>> How can I find the first space using regex?
>>
>> For example I have text
>> Text=' This is a sample '
> 
> Why do you need to use a regex?
> 
> text = text.replace(" ", "")

You are aware that this is producing nonsense given the OP's requirements?

>>> print Text.replace(" ", "")
Thisisasample

Instead, the OP wants

>>> print Text.strip()
This is a sample

Diez




More information about the Python-list mailing list