RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 2
Title Test Details Match Valid HTML Tags As Browser
Expression
<(/)?(a|abbr|acronym|address|applet|area|b|base|basefont|bdo|big|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dir|div|dfn|dl|dt|em|fieldset|font|form|frame|frameset|h[1-6]|head|hr|html|i|iframe|img|input|ins|isindex|kbd|label|legend|li|link|map|menu|meta|noframes|noscript|object|ol|optgroup|option|p|param|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|xmp){1}(\s(\"[^\"]*\"*|[^>])*)*>
Description
This should match all valid HTML 4.01 tags as a browser would recognize. If you miss a 2nd " it will continue until it finds one to pair with, so if it doesn't find one, it continues until the end. This is how most browsers work I believe. It does have a few flaws, it will match </img> and </input> which is weird, but perhaps I'll fix that eventually.
Matches
</a> <h2 > </h2 asfsdf> <a href="abc>>123">
Non-Matches
< /a> </h 2 asfsdf> <ahref="abc123">
Author Rating: The rating for this expression. John Smith
Title Test Details Match Valid HTML Tags
Expression
</?(a|abbr|acronym|address|applet|area|b|base|basefont|bdo|big|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dir|div|dfn|dl|dt|em|fieldset|font|form|frame|frameset|h[1-6]|head|hr|html|i|iframe|img|input|ins|isindex|kbd|label|legend|li|link|map|menu|meta|noframes|noscript|object|ol|optgroup|option|p|param|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|xmp)\b((\"[^\"]*\"|\'[^\']*\')*|[^\"\'>])*>
Description
This is very similar to my other expression, except it only matches tags that a browser would read, so if you have an extra " in the tag, it will not count it, and move onto the next possibility.
Matches
</a> <h2 > </a asdfs> </h2 asfsdf> <a href="abc>>123">
Non-Matches
< /a> </h 2 asfsdf> <ahref="abc"123">
Author Rating: The rating for this expression. John Smith
   Displaying page 1 of 1 pages; Items 1 to 2

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials