Skip to main content
Known Participant
October 17, 2025
Answered

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

  • October 17, 2025
  • 2 replies
  • 361 views

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>

Correct answer Eugene Tyson

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

 

 

2 replies

m1b
Community Expert
Community Expert
October 17, 2025

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

m1b
Community Expert
Community Expert
October 17, 2025

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

Community Expert
October 17, 2025

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 😛 

Community Expert
October 17, 2025

Find

\="\K\d+(?=")
Eugene TysonCommunity ExpertCorrect answer
Community Expert
October 17, 2025

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

 

 

EubhalAuthor
Known Participant
October 17, 2025

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