3zzy 3zzy - 3 months ago 25
CSS Question

Match only a specific tag

I need to find only the empty

<i>
tags which may or may not have attributes.

This matches
<i>
but also
<img>
and
<input>
:

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


How do I match only
<i>
tags?

Answer

You can just change the last part of regex to </i> right. This way it will not end up selecting input and img

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

EDIT: Version to catch and include any whitespace between the i tags:

<i[^>]*[^>]*>(\h+)*</i>

Will catch <i> </i>.