I have a large routine document that requires several Regular Expression find/replace searches. In order to speed this process up, I looked into writing a Dreamweaver Command to preform all of my searches in one swoop (referenced: https://forums.adobe.com/thread/1193750).
It sounds exactly what I need, so I get started using the example and so far it’s working great for some, however, my Regex find/replace are being ignored. The documentation on custom Dreamweaver commands is very brief and I can’t find any well answered use cases. I've tried adding/removing quotes/forward slashes around the expressions, but no luck with either.
My Regex commands work in a normal find/replace, but that's not the case now that it's in a Javascript file. Is my use of Javascript w/ Regex correct? Has anyone had any luck getting something like this to work?
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();
}
I actually have more to add, but I don't want to invest too much time into this if it's not going to fully work.
Thank you for taking a look.