While writing scripts to convert legacy ASCII based fonts to Unicode, I find that grep patterns that work fine in the InDesign find/replace window do not work at all with scripts. I have shown a couple of examples below. Any help would be greatly appreciated!
function postProcess(){
resetPrefs();
app.findGrepPreferences.findWhat = “(i)([\x{0900}-\x{097F}])”; app.findGrepPreferences.appliedFont = legacyFont;
app.changeGrepPreferences.changeTo = “$2$1”
app.activeDocument.changeGrep();
}
Another example:
resetPrefs();
app.findGrepPreferences.findWhat = “(,|\.|x|?†|‰|Š|‹|Œ|‘|’|“|”|š|›|œ|¡|¢|£|¤|¥|§|©|ª|«|®|°|²|±|²|¶|·|¸|º|»|¿|À|Â|Ã|Ä|Å|Æ|Ç|È|É|Ê|Ë|Ì|Í|ê|ë|ÿ|é|’|‡|Ї)(\x{07c})”
app.findGrepPreferences.appliedFont =legacyFontName;
app.changeGrepPreferences.changeTo = “$2$1”;
app.activeDocument.changeGrep();
All of these work perfectly fine in the find/replace dialog box.I have even tried to replace the grep expression with Unicode code points(to avoid any conflicts with grep reserved expressions). But no luck.
“\x{002C}|\x{002E}|\x{0078}|\x{007E}|\x{2020}|\x{2030}|\x{0160}|\x{2039}|\x{152}|\x{2018}|\x{2019}|\x{201C}|\x{201D}|\x{161}|\x{203A}|\x{153}|\x{00A1}|\x{00A2}|\x{00A3}|\x{00A4}|\x{00A5}|\x{00A7}|\x{00A9}|\x{00AA}|\x{00AB}|\x{00AE}|\x{00B0}|\x{00B2}|\x{00B1}|\x{00B2}|\x{00B6}|\x{00B7}|\x{00B8}|\x{00BA}|\x{00BB}|\x{00BF}|\x{00C0}|\x{00C2}|\x{00C3}|\x{00C4}|\x{00C5}|\x{00C6}|\x{00C7}|\x{00C8}|\x{00C9}|\x{00CA}|\x{00CB}|\x{00CC}|\x{00CD}|\x{00EA}|\x{00EB}|\x{00FF}|\x{00E9}|\x{2019}|\x{2021}|\x{160}|\x{2021}|)(\x{07c})”;
function resetPrefs() {
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findChangeTextOptions.includeFootnotes = true;
app.findChangeTextOptions.includeMasterPages = true;
app.findChangeTextOptions.caseSensitive = true;
app.findChangeTextOptions.includeHiddenLayers = true;
app.findChangeTextOptions.includeLockedLayersForFind = true;
app.findChangeTextOptions.includeLockedStoriesForFind = true;
}