Regular Expressions 101

Community Patterns

Extract favicon from html head meta links

-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 - a year ago