Hi I am still confused
$subject = "This sentence contain several 'azzz' words"; $pattern = "/az{2}/"; if (preg_match($pattern, $subject)) { echo 'Regular expression <b>found!</b>'; } else { echo 'Regular expression <b>not</b> found!'; }
the above code is returning true! ('Regular expression found!)
Shouldn't preg_match return false. My understanding is that pattern = "/az{2}/" means match an a followed by exactly zz (2 z's not 3). am i wrong?
Hi I am trying to learn regular expression and am getting some unexpected results!
$sentence = "This sentence contains several zzz ";
if(preg_match("/z{1}/",$sentence))
{
echo "Regular expression found!";
}
else
{
echo "Regular expression NOT found!";
}
The above code is echoing out “Regular expression found. I am confused. Shouldn't “/z{1}/” return true only if there is only one z in the string not zzz. What am I missing?
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.