You can use an assertion for that, as you just have to ensure that the searched words occur somewhen after an >
, or before any <
. The latter test is easier to accomplish as lookahead assertions can be variable length:
/(asf|foo|barr)(?=[^>]*(<|$))/
See also http://www.regular-expressions.info/lookaround.html for a nice explanation of that assertion syntax.