Is there a difference between using “*” or “?” in php preg_match ? or Is there an example ?
<?php
// the string to match against
$string = 'The cat sat on the matthew';
// matches the letter "a" followed by zero or more "t" characters
echo preg_match("/at*/", $string);
// matches the letter "a" followed by a "t" character that may or may not be present
echo preg_match("/at?/", $string);
*matches 0 or more?matches 0 or 1In the context of your particular tests you can’t tell the difference because the
*and?matches aren’t anchored or don’t have anything following them – they’ll both match any string that contains ana, whether followed by ator not.The difference matters if you had something after the match character, e.g.:
whereas with yours: