Skip to main content
Participant
August 25, 2023
Answered

GREP and Cross-Reference Find/Change

  • August 25, 2023
  • 3 replies
  • 495 views

Dear all, I'm asking for Your help.

I need to change some formula in a big book that includes cross reference. I've got repeating formula that goes like this:

Details - see page 171
Détails v. page 171
Detalles v. página 171
Dettagli v. pagina 171

The number of page is a cross-reference link which varies depending of product which it connects. My goal is to add another (polish) translation between french and spanish one. So I thought this sentence would work:

Find: (Détails v. page )(~v$)

Change: $1$2\nStronas\$2

Hovewer instead of getting right cross-reference to specific page, it changes page numer to the one, on which the sentence is located. Could You tell me, what I've done wrong?

Kind regards,

Piotr

This topic has been closed for replies.
Correct answer FRIdNGE

Simplically:

 

… using this simple Script:

 

var myDoc = app.activeDocument;
// Step 1
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "Détails v\\. page ~v\\r";
myFound = myDoc.findGrep();
var F = myFound.length;
for (var f = 0; f < F; f++) myFound[f].duplicate(LocationOptions.AFTER, myFound[f]);
// Step 2
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(Détails v\\. page) ~v\\r\\K\\1";
app.changeGrepPreferences.changeTo = "Stronas";
myDoc.changeGrep( );
app.findGrepPreferences = app.changeGrepPreferences = null;

alert("Done [" + F + "]")

 

(^/)  The Jedi

3 replies

FRIdNGE
FRIdNGECorrect answer
August 25, 2023

Simplically:

 

… using this simple Script:

 

var myDoc = app.activeDocument;
// Step 1
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "Détails v\\. page ~v\\r";
myFound = myDoc.findGrep();
var F = myFound.length;
for (var f = 0; f < F; f++) myFound[f].duplicate(LocationOptions.AFTER, myFound[f]);
// Step 2
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(Détails v\\. page) ~v\\r\\K\\1";
app.changeGrepPreferences.changeTo = "Stronas";
myDoc.changeGrep( );
app.findGrepPreferences = app.changeGrepPreferences = null;

alert("Done [" + F + "]")

 

(^/)  The Jedi

Robert at ID-Tasker
Legend
August 25, 2023

Page = Strona - without "s" at the end - probably should have been "~S" as it's GREP.

 

Robert at ID-Tasker
Legend
August 25, 2023

.

Peter Kahrel
Community Expert
Community Expert
August 25, 2023

You can't use GREP variables like that, it works only for literal text. Not for cross-references, footnotes, endnotes, etc.

Participant
August 28, 2023

Thank You!