Page 1 of 1

matching

Posted: Wed Mar 22, 2006 1:31 am
by s.dot
All of these seem to match, when they shouldn't! what am i doing wrong?

Code: Select all

if(!preg_match("#[\w]+#i","scott%")){
	die("does not match");
} ELSE {
     die("matches");
}

if(!preg_match("#\w+#i","scott%")){
	die("does not match");
} ELSE {
     die("matches");
}


if(!preg_match("#[a-z0-9_]+#i","scott%")){
	die("does not match");
} ELSE {
     die("matches");
}

Posted: Wed Mar 22, 2006 1:48 am
by feyd
you're missing start and end of string hooks

Code: Select all

if(!preg_match("#^[\w]+$#i","scott%")){
    die("does not match");
} ELSE {
     die("matches");
}

if(!preg_match("#^\w+$#i","scott%")){
    die("does not match");
} ELSE {
     die("matches");
}


if(!preg_match("#^[a-z0-9_]+$#i","scott%")){
    die("does not match");
} ELSE {
     die("matches");
}