我想更換(模板語言)來替換一個或多個問號,這樣的:的Javascript正則表達式和逃避建議需要
var translation = "this is a ???";
console.log(translation.replace(/(\?+)/g, "replacement")); //this is a replacement
但現在,我最近遇到了一個問題,即問號是實際上是一個問題,不應該逃脫。我決定去爲~
作爲逃避的性格,所以這不應該被轉義:
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 <-- ???
就怎麼做任何建議?經典的\
作爲逃避角色會讓我比~
更開心,但我遇到了問題。
轉義字符一般只轉義一個字符 - 這將是不尋常的'〜'逃脫*系列*的'?'。相反,編寫'〜?〜〜〜?' –
@ExplosionPills這是很有意義的,這實際上是一個很好的觀點。 –
需要jsfiddle鏈接的人可以在此工作 http://jsfiddle.net/A4SGh/ –