Re: preg_match problem
| From: | Németh Zoltán | Date: | Fri, 19 Jan 2007 14:45:48 +0000 |
| Subject: | Re: preg_match problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247396@lists.php.net to get a copy of this message | ||
On p, 2007-01-19 at 15:39 +0000, Roman Neuhauser wrote:
> # znemeth@alterationx.hu / 2007-01-19 15:25:38 +0100:
> > Hi all,
> >
> > I have a simple checking like
> >
> > if (preg_match("/[\w\x2F]{6,}/",$a))
> >
> > as I would like to allow all "word characters" as mentioned at
> >
> > http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
> > plus the '/' character, and at least 6 characters.
> >
> > But it throws
> >
> > Warning: preg_match(): Unknown modifier ']'
> >
> > and returns false for "abc/de/ggg" which string should be okay.
> > If I omit the "\x2F", everything works fine but "/" characters are not
> > allowed. Anyone knows what I'm doing wrong? Maybe "/" characters can not
> > be put in patterns like this?
>
> 1. You're making your life harder with those double quotes. \x2F is
> interpolated by PHP, before the PCRE library has a chance to see the
> string.
> 2. Use a different delimiter and you'll be able to use slash characters
> in the pattern freely.
>
> preg_match('~[\w/]{6,}~', $a);
>
Thank you very much, it's working fine now.
Zoltán Németh