I want to use regular expression for url. But my code is not working please help me I am new here. My url is like:
http://www.justdial.com/Delhi/Eagnatec--Opposite-Sun-Vally-International-School-Vaishali-Sector-1/011PXX11-XX11-120601182620-Y5P9_RGVsaGkgQ29tcHV0ZXIgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET - Eagnatec
and my code is:
<?php
$hh1='http://www.justdial.com/Delhi/Eagnatec--Opposite-Sun-Vally-International- School-Vaishali-Sector-1/011PXX11-XX11-120601182620- Y5P9_RGVsaGkgQ29tcHV0ZXIgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET - Eagnatec';
$date_regex='^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6} (?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\- ]+)*)$';
if (preg_match($date_regex,$hh1))
{
echo "correct";
} ?>
First, your pattern $date_regex
is missing delimiters .
Then, your pattern simply does not match the subject $hh1
:
http(?:s)?\\:\\/\\/[a-zA-Z0-9\\-]+(?:\\.[a-zA-Z0-9\\-]+)*
matches http://www.justdial.com
.
The following \\.
(escaped literal `.`) does not match the subject's next character /
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.