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.
- 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.
- 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" [^<>]*>
- 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.