[英]Replace string that starts with specific character and ends with specific character in regular expression
I wanted to replace a string section that starts with a specific character and ends with specific character. 我想替换以特定字符开头并以特定字符结尾的字符串部分。 At below, I demonstrate test case.
在下面,我演示了测试用例。
var reg = /pattern/gi;
var str = "asdfkadsf[xxxxx]bb";
var test = str.replace(reg,"") == "asdfkadsfbb"
console.log(test);
This pattern should work for replace anything between brackets (including the brackets): 此模式应用于替换括号(包括括号)之间的任何内容:
var reg = /(\[.*?\])/gi;
var str = "asdfkadsf[xxxxx]bb";
var test = str.replace(reg,"") == "asdfkadsfbb"
基于您的示例,这适用:
/\[.*]/gi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.