Re: Space in regex
| From: | Richard Lynch | Date: | Mon, 20 Nov 2006 23:12:23 +0000 |
| Subject: | Re: Space in regex | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244911@lists.php.net to get a copy of this message | ||
. means *ANY* character, unless you escape it for PCRE
\. is what PCRE needs.
So, in PHP, to get the \ down to PCRE, you want 2 \:
Then there is the issue that '-' looks like a "range" character (A-Z
etc) so you should put it at the end.
And there is no need to use the confusing (to me) ::xyz:: stuff...
'/[A-Za-z0-9\\'\\.& _-]/'
You can simplify this a bit to:
'/[A-Z0-9\\'\\.& _-]/i'
That assumes PCRE. If you've regressed to that ereg stuff, you're on
your own.
On Thu, November 16, 2006 3:08 pm, Dotan Cohen wrote:
> I'm trying to match alphanumeric characters, some common symbols, and
> spaces. Why does this NOT match strings containing spaces?:
> [A-Za-z0-9\'.&-:underscore::space:]
>
> I've also tried these, that also fail to match strings containing
> spaces:
> [A-Za-z0-9\'.&- :underscore:]
> [A-Z a-z0-9\'.&-:underscore:]
> [:space:A-Za-z0-9\'.&-:underscore:]
>
> All these regexes match strings containing the specified characters,
> but none of them match strings with spaces.
>
> Dotan Cohen
>
> http://what-is-what.com/
> http://technology-sleuth.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?