Software Developer

Sublime Text 3 – Regex to Find an Opening HTML Tag

These regular expression examples are useful in Sublime Text 3 when you enable “Find” by Regular Expression. You can search for an HTML element’s opening tag, with or without specifying attributes.

  1. This example will search for just the opening tag of an HTML element. In this case, it’s an “a” link element. You can change the “a” at the beginning to any HTML element that you need to search for. This example does not specify attributes, so it will find “a” tags that have any attributes, and also those that have no attributes.

    <a[^<>]*[^<>]*>
  2. This example will search for just the opening tag of an “img” image element (which doesn’t have a closing tag most of the time, anyway). You can change the “img” to any HTML element that you need to search for. This will search for only those tags with the “alt” attribute set to “some value”. You can change that to the attribute that you need, for example, title=”Some Image Title”.

    <img[^<>]*alt="some value" [^<>]*>
  3. This example is just like the one above, except that you don’t have to specify the value of the attribute. It will find any “img” tag that has an “alt” attribute set to any value.

    <img[^<>]*alt="[^"']+" [^<>]*>

By

We've One Response

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]