Javascript 正则表达式删除方括号内的html标记

Javascript 正则表达式删除方括号内的html标记,javascript,regex,Javascript,Regex,我使用Regex提取方括号内的内容:- string.match(/[^[\]]+(?=])/g) 但这不会提取方括号之间的字符串,例如 string=“[项目说明(仅适用于)]” 还有,删除方括号内html元素的正则表达式是什么 例如:- string="[<span>Description of project (only for)</span>]" string=“[项目说明(仅适用)]” 应用正则表达式后的输出应为“项目说明(仅适用于)” 匹配方括号中的所有

我使用Regex提取方括号内的内容:-

string.match(/[^[\]]+(?=])/g)
但这不会提取方括号之间的字符串,例如

string=“[项目说明(仅适用于)]”

还有,删除方括号内html元素的正则表达式是什么

例如:-

string="[<span>Description of project (only for)</span>]"
string=“[项目说明(仅适用)]”
应用正则表达式后的输出应为“项目说明(仅适用于)”

  • 匹配方括号中的所有内容

  • 使用回调函数替换此匹配内容中的html标记

  • 演示:
    var matches=“这是外部内容,内部是[项目说明(仅适用)]”。替换(/\[.*?\]/gi,函数(匹配){
    返回匹配。替换(/]*?>/gi',);
    });
    警报(火柴);
    
    阅读以下内容:您想要javascript格式的吗?或者什么语言?嘿,这不适用于像getcontent=[Assignment name][Total No of staff months of the Assignment]这样的东西在这里我不想丢失任何其他标签,除了方框内的标签brackets@user1744639,它也适用于此输入:
    var matches = "This is <span>Outside content </span> and inside is [<span>Description of project (only for)</span>]".replace(/\[.*?\]/gi,function(match) {
    
        return match.replace(/<\/?[^>]*?>/gi,'');
    
    });
    
    alert(matches);