The current code is excluding the test link but not the test
url.
Please see my current code here:
var regexp = new RegExp( "\\b(" + data.title + ")\\b(?![^<a]*>|[^<>]*</a>)" , 'i');
This regex is used by searching words from the content: test
Example Output: This is a test page.
The word 'test' will be highlighted and will be linked somewhere base on my dictionary.
Issue: If the content have this HTML tag. The URL with the word test will be highlighted as well and result to broken tags. URL should be excluded to regex.
Example: This is a <a href="https://sample.com/to-test/">test</a>
Please see the link of regex:
https://regex101.com/r/aamuTy/3
One option to exclude the text in <a>
tag is https://regex101.com/r/aamuTy/4
Pattern: <a.*?</a>|\b(estoppel)\b
Explanation:
<a>..</a>
tag.\b(estoppel)\b
. This way Group 1 will be available only if the second part of the pattern matches. We can only work on the values captured in Group1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.