mr_pablo Posted March 10, 2009 Share Posted March 10, 2009 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 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 10, 2009 Share Posted March 10, 2009 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"; } ?> Quote Link to comment Share on other sites More sharing options...
mr_pablo Posted March 10, 2009 Author Share Posted March 10, 2009 Champion, cheers mate, works a charm now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.