How do I match a regular expression like link/3445/65? the numbers are random and the last number may not exist.
Link /? ([0-9] {1 ,})/? ([0-9] {1 ,})/? $ Why is it wrong to write this? I don't know much about it. ask for help.
Reply to discussion (solution)
$s = "link/3445/644445";$reg = '/link\/([\d]*)\/([\d]*)$/i';preg_match($reg, $s, $a);print_r($a);
First, if you do not need to obtain the specific content in the matching, do not add parentheses everywhere. parentheses are used to obtain the content in the matching.
$ Reg = '/link \/\ d + \/\ d * $/I ';
$s = "link/3445/644445";$reg = '/link\/([\d]*)\/([\d]*)$/i';preg_match($reg, $s, $a);print_r($a);
I think [\ d] * is a bit redundant. The brackets indicate or mean that an element does not exist or can be directly put out. Personal Understanding ~
$s = "link/3445/644445";$reg = '/link\/([\d]*)\/([\d]*)$/i';preg_match($reg, $s, $a);print_r($a);
I think [\ d] * is a bit redundant. The brackets indicate or mean that an element does not exist or can be directly put out. Personal Understanding ~
Thanks for your guidance. actually, I am not familiar with regular expressions.
Thanks for learning.