I have the following regular expression, which I'm using to find <icon use="some-id" class="some-class" />
:
(?:<icon )(?=(?:.*?(?:use=(?:"|')(.*?)(?:"|')))?)(?=(?:.*?(?:class=(?:"|')(.*?)(?:"|')))?)(?:.*?)(?: \/)?[^?](?:>)
This mostly works, except that if I don't specify a class, but do specify one on another element on the same line, it'll match that other elements class, even though the full match is reported as just being the icon element.
For example:
<icon use="search" /> <div class="test"></div>
$1
for that is search
, and $2
is test
, even though they're not part of the same element. $&
is reporting <icon use="search" />
.
I'm sure I'm missing something obvious about the way regular expressions work.