Jump to content

[SOLVED] Simple preg_match expression not working, can't see why :(


mr_pablo

Recommended Posts

I have the following code testing an expression:

 

if(preg_match("(http://www)\.[^.]+\.[^.]{2,4}", "http://www.php.net")) {
echo "true";
} else {
echo "false";
}

 

the result keeps coming back false. I have checked the expression in Expresso and RegexBuddy and it works in both flawlessly.

 

Can anyone shed some light on why this is not working for me?

 

Thank you

You need to start and end the regular expression with a character...i use / but ~ is also common. In this case we'll use ~ since there is already a / in the expression

 

<?php
if(preg_match("~(http://www)\.[^.]+\.[^.]{2,4}~", "http://www.php.net")) {
   echo "true";
} else {
   echo "false";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.