[英]How to exclude <a> tags url to regex?
The current code is excluding the test link but not the test
url.当前代码不包括测试链接,但不包括
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此正则表达式用于从内容中搜索单词:test
Example Output: This is a test page.
示例 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.问题:如果内容具有此 HTML 标记。 The URL with the word test will be highlighted as well and result to broken tags.
带有单词 test 的 URL 也将突出显示,并导致标签损坏。 URL should be excluded to regex.
URL 应排除在正则表达式之外。
Example: This is a <a href="https://sample.com/to-test/">test</a>
示例:这是一个
<a href="https://sample.com/to-test/">test</a>
Please see the link of regex:
https://regex101.com/r/aamuTy/3 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排除
<a>
标记中的文本的一种选择是https://regex101.com/r/aamuTy/4
Pattern: <a.*?</a>|\b(estoppel)\b
模式:
<a.*?</a>|\b(estoppel)\b
Explanation:解释:
<a>..</a>
tag.<a>..</a>
标记中的任何内容。\b(estoppel)\b
.\b(estoppel)\b
。 This way Group 1 will be available only if the second part of the pattern matches.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.