简体   繁体   English

javascript替换字符串(正则表达式)

[英]javascript replace string (Regular expression)

I am trying to replace string 我正在尝试替换字符串

 <audio controls src='tempfile://b07b4667-62d6-432d-2dd7-feedd9255ea3'>

with empty using regular expression 使用正则表达式为空

I tried this way but it doenst work.. Here link is the audio string which i want to replace with empty.. 我尝试过这种方法,但是它确实起作用。.链接是我要替换为空的音频字符串。

return text.replace(/<\s*audio[^>]*>\s*<\s*\/\s*audio\s*>/ig, function (whole, a, b, c) {
            if (b == link) return '';
            else return whole;
        }); 

You can do it like the following way (using regex capture group ) : 您可以按照以下方式进行操作(使用regex capture group

 var str = "<audio controls src='tempfile://b07b4667-62d6-432d-2dd7-feedd9255ea3'>"; var emptyStr = str.replace(/([<\\s\\w='://\\->])/ig, ''); console.log(emptyStr); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM