我有一个大型的例程文档,需要几个正则表达式查找/替换搜索。为了加快这个过程,我编写了一个Dreamweaver命令,在一次搜索中预置我的所有搜索(引用:https://forums.adobe.com/thread/1193750)。
这听起来正是我所需要的,所以我开始使用这个例子,到目前为止,它对一些人非常有用,但是我的Regex查找/替换却被忽略了。关于自定义Dreamweaver命令的文档非常简短,我找不到任何答案良好的用例。我试着在表达式周围添加/移除引号/正斜杠,但两者都没有进展。
我的Regex命令在正常的查找/替换中工作,但现在它不在Javascript文件中。我对Javascript w/ Regex的使用正确吗?有人运气好吗?
function canAcceptCommand() {
return true;
}
function commandButtons() {
return new Array("Go!", "doIt()", "Cancel", "window.close()");
}
function doIt() {
var categoryTag = /<\/([A-Z]{2})>([^\r])<\1>/g;
dreamweaver.setUpFindReplace({
searchString: categoryTag,
replaceString: null,
searchWhat: "document",
searchSource: true,
matchCase: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
dreamweaver.setUpFindReplace({
searchString: "&",
replaceString: "&",
searchWhat: "document",
searchSource: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
var inlineRM = /(RM\s.*?,)/g;
var dropRM = /\n$1/;
dreamweaver.setUpFindReplace({
searchString: inlineRM,
replaceString: dropRM,
searchWhat: "document",
searchSource: true,
matchCase: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
var incorrectAmPmFormat = /AM(\s-\s)(.*\s)PM/g;
var correctAmPmFormat = /a.m.$1$2p.m./;
dreamweaver.setUpFindReplace({
searchString: incorrectAmPmFormat,
replaceString: correctAmPmFormat,
searchWhat: "document",
searchSource: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
dreamweaver.setUpFindReplace({
searchString: ":00",
replaceString: "",
searchWhat: "document",
searchSource: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
dreamweaver.setUpFindReplace({
searchString: "<fees aid:",
replaceString: "\n<fees aid:",
searchWhat: "document",
searchSource: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
var removeBothPMs = /\sPM(\s-\s)(.*\s)PM/g;
var replaceWithOnePM = /$1$2p.m./;
dreamweaver.setUpFindReplace({
searchString: removeBothPMs,
replaceString: replaceWithOnePM,
searchWhat: "document",
searchSource: true,
matchCase: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
var removeBothAMs = /\sAM(\s-\s)(.*\s)AM/g;
var replaceWithOneAM = /$1$2a.m./;
dreamweaver.setUpFindReplace({
searchString: removeBothAMs,
replaceString: replaceWithOneAM,
searchWhat: "document",
searchSource: true,
matchCase: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
var threeSpaces = /\s\s\s<Image href="file:\/\/\/Volumes\/Communications\/assets\/New.eps"><\/Image>/;
dreamweaver.setUpFindReplace({
searchString: "<new>NEW</new>",
replaceString: threeSpaces,
searchWhat: "document",
searchSource: true,
matchCase: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
dreamweaver.setUpFindReplace({
searchString: "><",
replaceString: ">\n<",
searchWhat: "document",
searchSource: true,
useRegularExpressions: true
});
dreamweaver.replaceAll();
window.close();
}事实上,我还有更多要补充的,但如果它不能完全发挥作用,我不想在这上面投入太多的时间。
谢谢你看一看。
发布于 2014-10-21 13:58:53
所以我抛弃了Dreamweaver。无论如何,我没有必要使用它(旧习惯应该消失)。对于那些仍在寻找解决方案的人,我建议采取类似的方法。我只是编写了一个Ruby脚本(感谢:How to search file text for a pattern and replace it with a given value),它完全满足了我的需要,但更优雅。Dreamweaver会在执行的命令负载下随机崩溃。
https://stackoverflow.com/questions/26426158
复制相似问题