我想用替换(模板语言)替换一个或多个问号,如下所示:
var translation = "this is a ???";
console.log(translation.replace(/(\?+)/g, "replacement")); //this is a replacement
但是现在,我最近遇到了一个问题,问号实际上是一个问题,不应该被转义。我决定使用~
as 转义字符,因此不应转义:
var translation = "this should not be escaped, cause it's a question, is it~?";
console.log(translation.replace(/[^~](\?+)/g, "replacement"));
工作至今。但是,如果我使用多个问号(模板语法的要求),我最终会得到废话:
var translation = "this should not be escaped, cause it's a question, is it~???";
console.log(translation.replace(/[^~](\?+)/g, "replacement"));
//this should not be escaped, cause it's a question, is it~replacement <-- ???
关于如何做到这一点的任何建议?一个经典\
的逃脱角色会让我比那个更快乐,~
但我也遇到了问题。