I need a regex pattern that will match the first occurrence of a word, not wrapped inside of an 'a' tag, but can be wrapped inside of any other tag.
i.e. negative lookahead to see if matching word is inside of an a' tag, if so ignore and keep looking for a valid match.
Example strings
Payload 1:
<p>Sample 1 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some random text
to not be matched followed by wordToMatch, this should work.</p>
Expected Result 1:
wordToMatch ("Not the one inside of a' tags but the following one")
Payload 2:
<p>Sample 2 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some random text
to not be matched followed by <b>wordToMatch</b> this should work.</p>
Expected Result 2:
wordToMatch ("The one inside of the b' tags")
Payload 3:
<p>Sample 3 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some
random text to not be matched followed by wordToMatch followed by
further occurrences of wordToMatch which should not be matched.</p>
Expected Result 3:
wordToMatch ("The second occurrence of the term")
Please help :'(
Language being used is Java