Re: Regular expression to find from start of string to first space
| From: | Dave Goodchild | Date: | Tue, 08 Aug 2006 11:13:26 +0000 |
| Subject: | Re: Regular expression to find from start of string to first space | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240304@lists.php.net to get a copy of this message | ||
On 08/08/06, Dave M G <martin@autotelic.com> 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