任何人都可以看到爲什麼下面的代碼不對所有{{...}}佔位符執行正則表達式操作?下面的輸入字符串只是原始版本的簡化版本。正則表達式替換未在所有匹配中執行
https://jsfiddle.net/2L12jr3u/2/
var input = "{{ %[email protected] }}/{{ %[email protected] }} ({{ %[email protected] }}) {{ %[email protected] }} {{ %[email protected] }} {{ %1$d }} {{ %[email protected] }} of {{ %2$d }} of {{ %3$d }}";
var regex = /(\{\{ \%(\d)\$(.) \}\})/g;
var match;
while (match = regex.exec(input)) {
console.log(match);
input = input.replace(match[0], '%@' + match[2]);
}
console.log(input);
應的結果是什麼樣的? – garryp