I'm looking for some feedback on the below regex string to be used by PHP to detect links to PDF files in a given string.
/href=["\']?[^"\'>]+(?:\.pdf)["\']?/
This seems to do what I want in cursory tests, but I'm wondering if it needs to be more robust for edge cases. For one thing, it doesn't limit to <a>
tags, just any element with a href
attribute containing .pdf
. Is there anything else I am missing? What about case sensitivity for .PDF
?