Re: Regular expression to find from start of string to first space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/08/06, Dave M G <martin@xxxxxxxxxxxxx> wrote:

PHP,

Shouldn't this regular expression select everything from the start of
the string to the first space character:

$firstWord = preg_match('#^*(.*) #iU', $word);

It doesn't, so clearly I'm wrong, but here's why I thought it would:

. stands for any single character, not *. Also, # is the delimiter, but
you can use a variety of deliimters. The following should work:


^[\w\d]+\s{1}

^ start of line
[\w\d]+ range of any digits or letters, one or more
(\s{1}) exactly one whitespace character

hope this helps!




--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux