Javascript 替换两个字符之间的多个字符串
它应该显示Javascript 替换两个字符之间的多个字符串,javascript,regex,replace,Javascript,Regex,Replace,它应该显示“这里被替换,替换那些**文本。” 注意-它应该处理**之间的动态字符串,而不仅仅是text1和text2您必须转义*,并在*之后使用?进行非贪婪匹配: const func=str=>str.replace(/\*\*.*?\*\*/g,'replaced'); log(func('这里是**text1**和**text2**替换那些**文本'); log(func('这里是**一些较长的文本****') str = “Here are \*\*text1\*\* and \*\*
“这里被替换,替换那些**文本。”
注意-它应该处理**之间的动态字符串,而不仅仅是text1和text2您必须转义
*
,并在*
之后使用?
进行非贪婪匹配:
const func=str=>str.replace(/\*\*.*?\*\*/g,'replaced');
log(func('这里是**text1**和**text2**替换那些**文本');
log(func('这里是**一些较长的文本****')代码>
str = “Here are \*\*text1\*\* and \*\*text2\*\* replace those **texts.”
console.log(str.replace(/\*\*.*\*\*/, ‘replaced’)); // Here are replaced texts.