Re: Regular expression to find from start of string to first space [SOLVED]
| From: | Dave M G | Date: | Wed, 09 Aug 2006 05:21:43 +0000 |
| Subject: | Re: Regular expression to find from start of string to first space [SOLVED] | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240355@lists.php.net to get a copy of this message | ||
Richard, Adam, Barry, Dave, David,
Thank you all for your helpful advice regarding expressions.
I was able to combine all your advice, and made some additional discoveries along the way.
The winning expression is:
"#^(.*)\s#iU"
First, I discovered that sometimes the source text had an unexpected space character at the very beginning. So I realized that I needed to do trim() to ensure proper functionality of the expression.
Next, it seems it's better to use \s than an actual space, " ". It might be the case that both are okay, but I've had success with \s, so I decided to stop experimenting.
I tried, as Adam suggested, to use substr() instead of a regular expression. The syntax he provided may work as far as finding the right text to extract. But I can't be sure because it seems to have problems with the character encoding.
The word being extracted is in UTF-8 encoded Japanese. The regular expression seems to input and output it fine. But I couldn't find a way of using the substr() function without the text coming out as ASCII gibberish.
So I'm calling this one solved for me, as I have working code. Although if anyone believes that it could be more efficient or something, of course I'm all ears.
Thank you for all your time and advice.
--
Dave M G