让Regex使用自定义Dreamweaver命令
Getting Regex to work with custom Dreamweaver commands
我有一个大型例程文档,它需要几个正则表达式查找/替换搜索。为了加快这个过程,我考虑编写一个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();
}
事实上,我还有更多要补充的,但如果它不能完全发挥作用,我不想在这方面投入太多时间。
谢谢你看。
所以,我放弃了Dreamweaver。不管怎样,我都没有必要使用它(旧习惯应该会消失)。对于那些仍在寻找解决方案的人,我建议采取类似的路线。我只是简单地编写了一个Ruby脚本(感谢:How to search file text for a pattern and replace with a give value),它完全符合我的需求,但要优雅得多。Dreamweaver会在执行命令的负载下随机崩溃。
相关文章:
- 当我点击jsf中的primefaces命令按钮时,如何获得点击事件
- 如何使用Socket.io将命令从客户端发送到服务器
- 通过命令行/批处理文件打开页面时,将javascript代码注入Google Chrome
- 命令行中的Uglify js;不要弄乱变量名
- http.listen()在运行时接受终端命令
- 如何在没有单词的情况下从命令行运行Node.js程序'节点'
- 如何将给定的curl命令复制为jquery ajax请求
- 打开抽屉的Javascript打印命令
- Web控制台命令不起作用
- 如何使用脚本在jsf中执行命令按钮的自动点击
- 类似HTML命令行的文本框
- 命令“;节点"做
- 节点JS express和控制台输出到命令行与浏览器
- 如何将.json文件作为参数导入.js文件并使用命令行启动它
- 编辑弹出窗口的HTML的单击命令
- 为什么我的关键命令不起作用
- Javascript不能在一个命令中使用函数参数
- 运行一个特定<脚本>(Dreamweaver)
- 最小化CSS/JS文件,并使用命令行创建一个文件
- 让Regex使用自定义Dreamweaver命令