REGEX – Multiple HTML usages

Any Specific Tag + Contents
Find specific tags and return them and their contents. In this case, I have used the invalid and little known “spaghetti” tag. Case insensitive for IE.

/<spaghetti[^>]*>(.|\n)*?<\/\s*spaghetti>/i

Meta – Charset
Find the given charset in the page contents. Returns the charset in variable 1. Case insensitive.

/<meta[^>]*charset=\"*([^\"<]+)/i

DocType
Find the given DOCTYPE of a page contents. Case insensitive.

/<!DOCTYPE[^>]*>/i

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

More in Code, Software, Tips (161 of 199 articles)


Valid Domain Matches a proper domain pattern. [php]/[^,\s]+\.{1,}[^,\s]{2,}/[/php] Sub-Domain Returns the sub-domain of a proper domain. [php]/^([^\.]+\.)/[/php] ...