[thelist] [php] '*' inside regexp (preg_match)

Ken Snyder ksnyder at coremr.com
Tue May 29 16:36:40 CDT 2007


Hi Paul,

If you want to allow a dash character, you have to escape it ("\-") or 
put the dash right before the bracket.  Right now you have 
space-dash-period (" -.") which will allow any character with an ascii 
code between space (32) and period (46) among which asterisk (42) 
happens to fall.  Try this:

preg_match("/^[a-zA-Z0-9 \-.(),]+$/", 'abc**def');


- Ken Snyder


Paul Bennett wrote:
> Hi people smarter than me,
>
> Discalimer: I'm a regexp retard (but I am getting better). In any case, can someone tell me why this returns true?:
>
> echo preg_match("/^[a-zA-Z0-9 -.(),]+$/", 'abc**def'); 
>
> Surely the regexp shouldn't allow the asterisk character to be in there??? Or does it have special meaning when used as a string inside preg_match?
>
> Confusedly yours,
> Paul 
>   




More information about the thelist mailing list