Answered
"replace" command doesn't work.
- December 28, 2023
- 2 replies
- 435 views
Hi;
I find the paragraphs I want. I want to replace the number after the word "Key" with qq in the "Key qq" section. I wrote a simple js, but I think the replace command doesn't work.
Thanks....
#target indesign
redraw = app.scriptPreferences.enableRedraw;
app.scriptPreferences.enableRedraw = 0;
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Mehmet! …");
app.scriptPreferences.enableRedraw = redraw;
function main()
{
var myDoc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat= "(?s)(Madde qq).+?\\r^\\d+\\r^(.+?\\r)";
//~ app.findGrepPreferences.appliedCharacterStyle = myCharStyle;
var myParas = myDoc.findGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
var P = myParas.length;
for ( var p = 0 ; p < P; p++ ) {
var myMatch = myParas[p].contents.match(/Key\s*(\d+)/gi);
alert (myMatch);
var keyNumber = Number(myMatch[1]);
alert (keyNumber);
myParas[p].contents.replace("qq", keyNumber);
}
}

