I have got many topics on extracting all urls from a string and detecting urls with specific pattern. But not both. Sorry I am a bit rough in regex. Can someone please help.
Here is what I want:
$str = <<<EOF
This string is valid - http://example.com/products/1
This string is not valid - http://example.com/order/1
EOF;
Basically I want to extract all urls inside the $str variable which has a patter with /products/
I tried this for the url extraction - /\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i but along with this I only want those having that pattern and not the others.
/products/so you could add it right?\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*\/products\/[-a-z0-9+&@#\/%=~_|]http://example.com/products/1/abcit just pulls upto the1and not the entire url.\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*\/products\/[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]regex101.com/r/KatX8u/1