2014-10-17 55 views
1

我有一个大的例程文档,需要几个正则表达式查找/替换搜索。为了加速这个过程,我考虑编写一个Dreamweaver命令,以便一次执行我所有的搜索(参考:https://forums.adobe.com/thread/1193750)。获取正则表达式以使用自定义Dreamweaver命令

这听起来正是我需要的,所以我开始使用这个例子,到目前为止它对一些工作很好,但是,我的正则表达式查找/替换被忽略。自定义Dreamweaver命令的文档非常简短,我无法找到任何解决方案。我已经尝试在表达式中添加/删除引号/正斜杠,但没有任何运气。

我的正则表达式命令在正常的查找/替换中工作,但现在不是这种情况,因为它在Javascript文件中。我使用的Javascript /正则表达式是否正确?有没有人有任何运气得到这样的工作?

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: "&amp;", 
    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

所以,我放弃了Dreamweaver。无论如何,我没有必要使用它(旧习惯应该死亡)。对于那些仍在寻找解决方案的人,我建议采取类似的方法。我只写了一个Ruby脚本(感谢:How to search file text for a pattern and replace it with a given value),它完全符合我的需求,但更优雅。 Dreamweaver会在执行的命令的加载下随机崩溃。