var stringVal = "../folder1/folder2/image1.jpg";
stringVal = stringVal.replace(/[../]/g , "");


它将替换字符串的所有/,但是我只想替换../

那怎么办

最佳答案

您可以使用正则表达式\.{2}\/




[../]character class,表示any character from . or /




var stringVal = "../folder1/folder2/image1.jpg";
stringVal = stringVal.replace(/\.{2}\//g, "");

document.write(stringVal);

08-16 15:26