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

Replace a letter using GREP without interfering in the GREP syntax

Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Hello!

Before the letter D, I try to insert a Column Break (in GREP is the character ^M) in my Index. But I can't because in GREP ^D means other thing and is not working the script.

Is important be sure don't damage other letters D

How can I add a column break before my single letter D ?

replaceText ("^D\r","^MD\r")

function replaceText (input, output) 

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 

     app.findTextPreferences.findWhat = input; 

     app.changeTextPreferences.changeTo = output; 

     app.activeDocument.changeText(); 

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  

}

My actual Index:

Screen Shot 2018-05-11 at 16.22.59.png

The result I expect:

Screen Shot 2018-05-11 at 16.23.27.png

Thanks so much in advance!

TOPICS
Scripting

Views

681

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 Expert , May 11, 2018 May 11, 2018

You cannot use changeGrep with TextPreferences syntax.

This should work.

replaceText ("^(D)$","~M$1")

function replaceText (input, output)

{

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

Have fun

Votes

Translate

Translate
Community Expert ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Try this:

SpaltenumbruchVorD.png

Have fun

Aktualisiert

(too much security)

^(D)$  is sufficient

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Hi !

Is funny because in Indesign using the normal Panel Find/change is working.

But with my code is not working. Do you thing this kind of GREP are not working in the scripts? or maybe is something wrong in my script?

replaceText ("^()$","~M$1")

function replaceText (input, output)

{

    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

    app.findTextPreferences.findWhat = input;

    app.changeTextPreferences.changeTo = output;

    app.activeDocument.changeText();

    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

}

Thanks a lot !

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

You cannot use changeGrep with TextPreferences syntax.

This should work.

replaceText ("^(D)$","~M$1")

function replaceText (input, output)

{

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

Have fun

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

HI!

works excelent.

Deep thank you!

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

here my final script, maybe help to someone:

// Source: https://forums.adobe.com/thread/708641

// This Script allow you to find a replace a Text using 2 syntax FIND or GREP. Becarefull, affects the text of the entire document. The sintaxis of your queries are different if you use FIND or GREP, exaclty same like when you find and replace with the indesign window.

// https://helpx.adobe.com/indesign/using/find-change.html#find_and_change_objects

// To replace with GREP a simple Index Setion Heading, for example the letter D, you can use simple this ^(D)$ but if you want extra security use this ^()$

/******** FIND AND REPLACE TEXT USING GREP ********/

replaceTextUsingGREP ("^()$","~M$1"); // add a Break Column before letter D (Index Section Heading)

function replaceTextUsingGREP (input, output)

{

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

/******** FIND AND REPLACE TEXT USING FIND ********/

replaceTextUsingFIND ("yourText", "^MyourText");  //add a Break Column

replaceTextUsingFIND ("yourText2\r", "yourText2\r");  // add many queries as you want

function replaceTextUsingFIND (input, output) 

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 

     app.findTextPreferences.findWhat = input; 

     app.changeTextPreferences.changeTo = output; 

     app.activeDocument.changeText(); 

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  

}

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

You're welcome.

(But please change 'extra security' to 'unnecessary'.)

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Here the final code, thanks to pixxxel schubser!

// Source: https://forums.adobe.com/thread/708641 

// This Script allow you to find a replace a Text using 2 syntax FIND or GREP. Becareful, affects the text of the entire document. The sintaxis of your queries are different if you use FIND or GREP, exactly same like when you find and replace with the indesign window.

// https://helpx.adobe.com/indesign/using/find-change.html#find_and_change_objects 

// To replace with GREP a simple Index Section Heading, for example the letter D, you can use simple this ^(D)$ but if you want unnecessary use this ^()$

/******** FIND AND REPLACE TEXT USING GREP ********/

replaceTextUsingGREP ("^(D)$","~M$1"); // add a Break Column before letter D (Index Section Heading) 

function replaceTextUsingGREP (input, output) 

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    app.activeDocument.changeGrep(); 

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 

}

/******** FIND AND REPLACE TEXT USING FIND ********/

replaceTextUsingFIND ("yourText", "^MyourText");  //add a Break Column

replaceTextUsingFIND ("yourText2\r", "yourText2\r");  // add many queries as you want

function replaceTextUsingFIND (input, output)  

{  

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;  

     app.findTextPreferences.findWhat = input;  

     app.changeTextPreferences.changeTo = output;  

     app.activeDocument.changeText();  

     app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;   

}

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

LATEST

manuelb27477138  schrieb

… you can use simple this ^(D)$ but if you want unnecessary use this ^()$  …

That's really funny. I'm amused. Thank you

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