1

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: "&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();
}

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.

knice
  • 391
  • 2
  • 8

1 Answers1

0

So, I've ditched Dreamweaver. It wasn't necessary that I use it anyway (old habits should die). For those still searching for a solution, I'd suggest taking a similar route. I simply wrote a Ruby script (thanks to: How to search file text for a pattern and replace it with a given value) that does exactly what I need, but much more gracefully. Dreamweaver would randomly crash under the load of executed commands.

Community
  • 1
  • 1
knice
  • 391
  • 2
  • 8