Advanced Search - Matching html Tags

It is not difficult to find html tags and to find start tags with their matching end tags.

This could be useful for checking your html. It uses grouping with a back reference.

Find html start tags:

Search "<"{AD}+ * ">"
This searches for "<" followed by one or more Alpha numeric characters. So this won't include the space after the tag name.

We can put two markers (@1 and @2) in there to pick out the tag name itself:

Search "<"@1{AD}+@2 * ">"

And then we use those markers as a "back reference" to search for the matching end tag:

Search "<"@1{AD}+@2 * ">" * ("</" @12">")
This adds some to the second example - search forward in line for "</" @12">" - these are within brackets to group them - so will only match </ followed by the tag name.

We only used a single * to search forward in the line so his will only find tags that start and end on a single line. Use ** to search for tags like <div> which span several lines.

Of course you can seach for specific tags. Just replace the {AD}+ with, for instance "table" (with the parentheses) to find tables.

Search "<"@1"table"@2 * ">" ** ("</" @12">")

Was this page helpful? Please email me and/or rate this page:


If you want a reply make sure any email address @torrens.org will not get spam-binned!
Optional comment

Other relevant pages

Top of page


Page Information

http://css.torrens.org/valid-html401-bluehttp://css.torrens.org/valid-css Document URI: http://stronged.torrens.org/man/search/examples/html_tag.html
Page first published Sunday the 21st of January, 2018
Last modified:Mon, 08 Jul 2024 09:18:36 BST
© 2018 - 2024 Richard John Torrens.