将字符串与正则表达式外部图像匹配,将 href 标签与 JavaScript 匹配

match strings with regex outside image and href tag with javascript

本文关键字:匹配 标签 JavaScript href 图像匹配 字符串 正则表达式 外部      更新时间:2023-09-26

我正在尝试将单词与 <a></a><img /> 标签之外的正则表达式匹配我有以下代码,仅匹配所有标签之外的字符串

/test(?!.*<'/)/g

a标签之间的测试字符串不应与后两个标签匹配

<a>test</a>  test lorem test

有什么想法吗?

这应该可以完成工作:

var string = "hello<a asdf>hello</a>hello";
var regex = /(.*?)<a.*?>.*?<'/a>(.*?)/g;
console.log(regex.exec(string));