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

From: Date: Tue, 08 Aug 2006 11:45:31 +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-240306@lists.php.net to get a copy of this message
Dave M G schrieb:
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: The enclosing has marks, "#", I *think* just encloses the expression. I was told to use them before, but I can't find them here: http://jp2.php.net/manual/en/reference.pcre.pattern.syntax.php The caret, "^", says to start at the beginning of the line. The first asterix, "*" after the caret says to use any starting character. The space just before the second "#" is the closing character of my search. The "(.*)" in the middle says to take anything in between the beginning of the line and the space. "iU" says, "be case insensitive, and don't be greedy". So, it should start at the beginning of the line and get everything up to the first space. But it doesn't work. Where did I go wrong? -- Dave M G http://www.rexv.org/
This is a quite good site to learn and test regexpressions. Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

« previous php.general (#240306) next »