I looked everywhere for an answer, but it seems I cannot get my head around preg_match functionality. I want to preg_match the link below where only the numbers part (the ID) is dynamic.
Link:
http://video.cnbc.com/gallery/?video=3000024508
Here goes what I have come up until now:
preg_match( '/^http://video.cnbc.com/gallery/?video=([0-9_-]/', $content )
But it won’t work.
RegExr Demo
Besides problems that others mentioned (escaping the
?and.and using#instead of/) you are also missing a+from after the number group ([0-9_-]), which means that group can be repeated.If you need to check if a string includes this kind of link or not, remove
^and$:preg_match('#http://video\.cnbc\.com/gallery/\?video=([0-9_-]+)#', $content);