Reputation: 49
Im looking to 'preg_match' a link that looks like /dp/B0039SD7S6/blah-blah my current expression looks like...
$var = preg_match('/dp\/(.?*)\//', $output);
This doesn't output '039SD7S6'. Im assuming because the backslashes interfere with the delimiter. Help would be appreciated, Thanks.
Upvotes: 1
Views: 166
Reputation: 11689
There are 3 problems with your regex:
?
must be after .*
preg_match
syntax: result must be in parameters, not in returning value.Change in this way:
preg_match('/dp\/(.*?)\//', $output, $var);
Or - as I prefer - in this way:
preg_match('{dp/(.*?)/}', $output, $var);
Upvotes: 2