Robert,

Thank you for your quick response and helpful advice.
Use preg_match() and pay special attention to the manual as it refers to
the third parameter :) The expression you need follows:
   "#^([^\\s]*)\\s(.*)$#U"

This works perfectly.

I now see that the preg_match() function returns an array with the original text, the selected text, and the discarded text. That wasn't clear to me before when I wasn't looking for that kind of behavior. But now that you point it out I see how it works.

But I am still confused about the expression you used. I can't quite break it down:
The opening "^" says to start at the beginning of the line.
The brackets indicate a sub-expression.
The square brackets indicate a character class (?).
The "^" inside the square brackets means "not".

First question, why is there an extra backslash before the space marker "\s"? Isn't that an escape character, so wouldn't that turn the following space marker into a literal backslash followed by an "s"?

The "*" says to select everything matching the preceeding conditions.

There's that double backslash and "s" again.

Hmm... does the (.*) after the second "\s" mean to match all the whitespace found? For example if there happened to be two space characters instead of just one?

The PHP manual says the "$" means to "assert end of subject". Which I think means "stop looking for any more matches".

So basically I'm confused about the extra escape slashes.

--
Dave M G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to