var layerName = layer.name;
//replace weird characters in layer names
var layerName = layerName.replace(")", "-");
var layerName = layerName.replace("(", "-");
var layerName = layerName.replace(":", "-");
var layerName = layerName.replace(":", "-");
var layerName = layerName.replace(/\//, "-");
var layerName = layerName.replace('/', "");
var layerName = layerName.replace("---", "-");
var layerName = layerName.replace("--", "-");
var file = new File(folder.fsName+"/"+layerName+".png");
使用extendscript但由于某种原因它不会替换两个“ - ”字符。我觉得我可以用正则表达式更轻松地做到这一点,但我很沮丧。我试图用“ - ”
替换所有奇怪的非字母数字字符和空格答案 0 :(得分:2)
这个怎么样:
// Test String
var layerName = "123---A%*^% )()H";
layerName
.replace(/\-+/g,'-') // Collapse multiple dashes into a single one
.replace(/\W+/g,'-'); // Replace Non-word characters
结果:
123-A-H
\W+
匹配所有非单词字符
答案 1 :(得分:0)
你想要的正则表达式是:
[^a-zA-Z0-9]
你的替换字符是' - '