RE: [PHP] Space in regex
| From: | Ford, Mike | Date: | Tue, 21 Nov 2006 11:25:38 +0000 |
| Subject: | RE: [PHP] Space in regex | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-244945@lists.php.net to get a copy of this message | ||
On 20 November 2006 23:12, Richard Lynch wrote:
> . means *ANY* character, unless you escape it for PCRE
>
> \. is what PCRE needs.
Not in a character class -- inside [], "." means ".".
> 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\\'\\.& _-]/'
Except now you have a syntax error, as you've failed to notice (as did several others) that the
\' in the original string is to escape the ' for PHP because the whole pattern string
itself is single quoted.
>
> You can simplify this a bit to:
> '/[A-Z0-9\\'\\.& _-]/i'
So the syntactically-correct simple version of this is '/[A_Z0-9\'.&_-]/i'.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm