I got the following code snipped from a popular website, for PHP regex validation.
I'm a novice and am playing around with regex. When I put a colon ":" in front of the URL, for $website as below (":www.xxx.com"), the expression still matches. I can't figure out why this should match. (for instance, $website = "zwww.xxx.com" doesn't match, which is expected). I tried regex 101, and thought the behavior might have something to do with the \b at the beginning of the regex, but even when I remove the \b, it still matches on ":www.xxx.com" or "&www.xxx.com", etc.) Many thanks for explaining!
<?php
$website = ":www.xxx.com";
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*
[-a-z0-9+&@#\/%=~_|]/i",$website)) {
echo "Matched!";
} else {
echo "Not Matched!";
}
?>