regex - pdf regexp match on php -


regexp isnt 1 of strong skills need bit of on this, have regexp pdf url on site source code

if (preg_match("/http\:\/\/.*?\.pdf/i", $source)) { 

which work ok of times of example when sites link urls like

http://doc.pdfsomething.com/somemore/name.pdf

i getting match http://doc.pdf , not complete pdf url.

any regexp guru, appreciated.

you can try matching on word boundary

preg_match("/http:\/\/.*?\.pdf\b/i", $source) 

meaning .pdf matched if there non-word character after pdf such ", whitespace, etc..

alternatively, if know url going followed specific character (double quotes " ?), use

preg_match("/http:\/\/.*?\.pdf\"/i", $source) 

Comments