Reply To: TOC and multiple identical entries

Home Page / Forums / General InDesign Topics (CLOSED) / TOC and multiple identical entries / Reply To: TOC and multiple identical entries

#86257
Ari Singer
Member

Kai, your GREP string only seems to work in sets of two and not when there are multiple instances.

Valentin, here’s the updated script that should work as expected. But be aware that it will not work when there’s a regular space between the entry and the number, only a tab is allowed. So make sure that all the entries have proper tabs before the number.

Please let me know if this does work.

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Fix Duplicate TOC Entries");

function main() {
    var myDoc = app.activeDocument;
    cleanPrefs();
    app.findGrepPreferences.findWhat = "(.+?)sd+r(1sd+r)+";
    var foundText = myDoc.findGrep();
    for (var i = foundText.length - 1; i >= 0; i--) {
       var curEntry = foundText[i];
        app.findGrepPreferences.findWhat = "r(?=.)";
        app.changeGrepPreferences.changeTo = ",s";
        curEntry.changeGrep();
        app.findGrepPreferences.findWhat = "(?<=, )(.+?)t(?=d+)";
        app.changeGrepPreferences.changeTo = "";
        curEntry.changeGrep();
        }      
    cleanPrefs();
    }

function cleanPrefs() {
    app.findGrepPreferences = app.changeGrepPreferences = null;
    }

This article was last modified on July 4, 2016

Comments (0)

Loading comments...