Regular Expressions 101

Community Patterns

1...34567...902

Community Library Entry

-1

Regular Expression
ECMAScript (JavaScript)

/
<link *.*(?: *href="([^"]*(\.png|\.ico))"| *type="(?:image\/png|image\/vnd\.microsoft\.icon|image\/x-icon)"| *rel="(?:icon|shortcut icon|apple-touch-icon)").*>
/
gim

Description

I needed a generic way to pull the shortcut icon for sites. This expression parses the html for the icon. If the icon was not found, my code checks for the "favicon.ico" in the root of the site.

Submitted by groundh0g - 2 years ago