Skip to main content
Known Participant
Oct 17, 2025 12:44 PM UTC
Answered

Is it possible to do an operation on a found digit in indesign?

Basically I need to increase every digit in bold underline(bold underline for emphasis, not in original document) in the text below (just an example of much larger document) by 1 and I'm hoping there's some GREP or plug-in way to do it. If anyone has any ideas outside of indesign, I'm open to them too (word or excel etc!). Thanks in advance!

 

 <navMap>
    <navPoint id="d3-d333afd81907b-d1e86" playOrder="1">
      <navLabel>
        <text>Title Page</text>
      </navLabel>
      <content src="OEBPS/9780008216528_epub_tp.xhtml"/>
    </navPoint>
    <navPoint id="d3-d333afd81907b-d1e107" playOrder="2">
      <navLabel>
        <text>Copyright</text>
      </navLabel>
      <content src="OEBPS/9780008216528_epub_cop.xhtml"/>
    </navPoint>
    <navPoint id="itocmarker" playOrder="3">
      <navLabel>
        <text>Table of Contents</text>
      </navLabel>
      <content src="OEBPS/9780008216528_epub_itoc.xhtml"/>
    </navPoint>
    <navPoint id="d4-dd0ff6d8ed905-d1e101" playOrder="4">
      <navLabel>
        <text>Prologue</text>
      </navLabel>
      <content src="OEBPS/9780008216528_epub_chap001.xhtml"/>
    </navPoint>

Eugene TysonCorrect answer
Community Expert
Oct 17, 2025 12:59 PM UTC

I'm such a ditz at times 
You want to increase by 1 like playorder 1 becomes playorder 2 -------- sigh I thought just meant in size or something.

This has come up before and I have a similar script so have something here that works. 

(function () {
    if (app.documents.length === 0) {
        alert("No document open.");
        return;
    }

    var doc = app.activeDocument;
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;

    // Match only numbers within playOrder="###"
    app.findGrepPreferences.findWhat = '(?<=playOrder=")\\d+(?=")';

    var results = doc.findGrep();
    if (results.length === 0) {
        alert("No playOrder numbers found.");
        return;
    }

    for (var i = 0; i < results.length; i++) {
        var num = parseInt(results[i].contents, 10);
        if (!isNaN(num)) {
            results[i].contents = (num + 1).toString();
        }
    }

    alert("All playOrder values have been increased by 1.");

    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
})();

 

 

7 replies

m1b
Community Expert
Community Expert
Oct 17, 2025 12:59 PM UTC

You beat me to it @Eugene Tyson I used exactly the same grep—great minds think alike! 🙂 Here's a demo document to help.

- Mark

Translate
m1b
Community Expert
Community Expert
Oct 17, 2025 1:00 PM UTC

Haha @Eugene Tyson speaking of great minds again.. I thought exactly what you did. Now I read it properly. Sorry OP!

Translate
Community Expert
Oct 17, 2025 1:01 PM UTC

Yeh the increasing the number thing has come up before on the forums for scripting, it's in my library already. So was an easy one 😛 

Translate
Community Expert
Oct 17, 2025 12:52 PM UTC

Find

\="\K\d+(?=")
Translate
Eugene TysonCommunity ExpertCorrect answer
Community Expert
Oct 17, 2025 12:59 PM UTC

I'm such a ditz at times 
You want to increase by 1 like playorder 1 becomes playorder 2 -------- sigh I thought just meant in size or something.

This has come up before and I have a similar script so have something here that works. 

(function () {
    if (app.documents.length === 0) {
        alert("No document open.");
        return;
    }

    var doc = app.activeDocument;
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;

    // Match only numbers within playOrder="###"
    app.findGrepPreferences.findWhat = '(?<=playOrder=")\\d+(?=")';

    var results = doc.findGrep();
    if (results.length === 0) {
        alert("No playOrder numbers found.");
        return;
    }

    for (var i = 0; i < results.length; i++) {
        var num = parseInt(results[i].contents, 10);
        if (!isNaN(num)) {
            results[i].contents = (num + 1).toString();
        }
    }

    alert("All playOrder values have been increased by 1.");

    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
})();

 

 

Translate
EubhalAuthor
Known Participant
Oct 17, 2025 1:33 PM UTC

You are my favourite human on the planet, thank you so much!!!

Translate