So I want to check if a string is in the format:
checkout/00/payment
where 00 can be any number.
I tried using preg_match to do this, but it didn’t work out:
if(preg_match('/checkout/ [0-9] /payment/', $url, $matches)){
echo 'hello';
}
Further I want it to fail if the string has any characters after the word ‘payment’
e.g checkout/00/payment/more
The following regex below now matches as you would expect. Notice that I surrounded the digits with parenthesis. This captures the number in $matches so you can use it later.
This code produces the following output:
preg_match manual page
preg_match_all manual page
PCRE regex syntax manual page
Possible modifiers in regex patterns