我有一个大型例行文档,需要几个正则表达式查找/替换搜索。为了加快这个过程,我研究了编写一个Dreamweaver命令,以便一举完成所有搜索(引用:https://forums.adobe.com/thread/1193750)。
这听起来正是我需要的,所以我开始使用这个例子,到目前为止它对某些人来说很有用,但是,我的正则表达式查找/替换被忽略了。自定义Dreamweaver命令的文档非常简短,我找不到任何得到很好解答的用例。我尝试在表达式周围添加/删除引号/正斜杠,但两者都没有运气。
我的正则表达式命令在正常的查找/替换中工作,但现在它不是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();
}
我实际上还有更多需要补充的内容,但如果它不能完全发挥作用,我不想投入太多时间。
感谢您一看。
答案 0 :(得分:0)
所以,我放弃了Dreamweaver。无论如何我都没有必要使用它(旧的习惯应该死亡)。对于那些仍在寻找解决方案的人,我建议采取类似的方法。我只是写了一个Ruby脚本(感谢:How to search file text for a pattern and replace it with a given value),它完全符合我的需要,但更优雅。 Dreamweaver会在执行命令的负载下随机崩溃。