• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How print grep search result and use it on another search

Community Beginner ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

Hi

I wanna find a pattern and then add something to that and search it again here my code

app.findGrepPreferences.findWhat = "^PP[0-9]{6,6}?$";

   

    var skunumber=app.activeDocument.findGrep();

    var skupp= skunumber+"-pp"

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

app.findTextPreferences.findWhat = skupp;

var finds = doc.findText();

if (finds.length > 0) {

 

alert("Found " + finds.length + " items, the first of them is on page " + finds[0].parentTextFrames[0].parentPage.name);

}

else {

alert("Nothing has been found");

}

    app.changeGrepPreferences.changeTo = finds[0].parentTextFrames[0].parentPage.name; 

    alert(app.activeDocument.changeGrep().length); 

     

    app.activeDocument.changeGrep(); 

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

but it doesn't find the    skupp ?

how can I user the grep find value in my code?

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Apr 21, 2017 Apr 21, 2017

here some the solution:

Since contents is a simple Javascript string (not native InDesign text anymore), you can use Javascript's own match function:

app.findGrepPreferences.findWhat = "(\\d)+(\\d)";
found
= app.activeDocument.findGrep();
m
= found[0].contents.match (/(\d)+(\d)/);
alert
(m.join('\n'));

Votes

Translate

Translate
Community Beginner ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

here some the solution:

Since contents is a simple Javascript string (not native InDesign text anymore), you can use Javascript's own match function:

app.findGrepPreferences.findWhat = "(\\d)+(\\d)";
found
= app.activeDocument.findGrep();
m
= found[0].contents.match (/(\d)+(\d)/);
alert
(m.join('\n'));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

LATEST

Since contents is a simple Javascript string (not native InDesign text anymore) …

Hi,

FWIW: The value of text.contents could also contain values like special characters expressed as enumerators.

Code and result:

app.findGrepPreferences.findWhat = "\\X";

var found = app.activeDocument.findGrep();

for(var n=0;n<found.length;n++)

{

    $.writeln(n+"\t"+found.contents.constructor.name);

};

/*

  

0    Enumerator

1    Enumerator

2    String

  

*/

Simple text frame in the document:

TextFrame-Contents-Enumerator-String.png

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines