You can try this pattern:
[Nn]issan(?=[^<>]*<)(?!(?:(?!</?(?:a|span)[ >/])(?:.|\n))*</(?:a|span)>)
It has one flaw that I'm aware of, which is that nested <a>
or <span>
tags can trip it up, causing it to match stuff like this:
<a>nissan<span></span><a>
See demo.
Explanation:
[Nn]issan
(?= # make sure it's not inside an <a> or <span> tag, like <a href="nissan">
# to do that, we'll assert that the next "<" occurs before ">".
[^<>]*
<
)
(?! # next, make sure it's not enclosed in an <a> or <span> tag like <a>nissan</a>
# to do that, we'll match anything up to the next "a" or "span" tag, either opening or closing, and then assert the tag is opening.
(?: # while...
(?! #...there is no opening or closing "a" or "span" tag
<
/?
(?:
a|span
)
[ >]
)
(?: # consume the next character.
.|\n
)
)*
# then assert the tag is not closing.
</
(?:
a|span
)
>
)