Skip to main content
hurix
Inspiring
May 8, 2013
Answered

Find and change GREP characters

  • May 8, 2013
  • 2 replies
  • 4451 views

Hi,

Is It possible to find and change a word (or character style)  in the end of each paragraph line from a finded text.

Is It possible to do this with a script?

my Script

app.findGrepPreferences.appliedCharacterStyle = "Italic";

myFind = myDoc.findGrep();

for(i=0; i<myFind.length;i++){

       myIndex = myFind.paragraphs[-1].parentStory.characters[myFind.index-1];
    myIndex.contents  =  SpecialCharacters.EM_SPACE;
}
But its find all the italic styles and insert EM space.
I need to change only the end of the line character Style("Italic")

Any help would be great.

Hurix

This topic has been closed for replies.
Correct answer Trevor:

change "Italic" to "italic", no need for a link I think

Not sure about that, if you don't have a c style called Italic you would get an error so send a link to some pages

Message was edited by: ~ Trevor ~


Hi Hurriz

To look for a font and style replace the following line

    app.findTextPreferences.appliedCharacterStyle = "Italic";

with

app.findTextPreferences.appliedFont = "Times New Roman\tItalic";

Separate the name of the font "Times New Roman" and the style name "Italic" with and only with "\t"

Make sure that you Spell and capitalize  the  font and style names precisely

One could also use 2 lines instead of 1 if one is scared of things like \t !

app.findTextPreferences.appliedFont = "Times New Roman";

app.findTextPreferences.fontStyle = "Italic";

If one wanted to one could put the cursor on text with the font type and style that one is looking for and use

app.findTextPreferences.appliedFont = app.selection[0].appliedFont;

That can be useful if one has for some reason a problem getting the correct font details.

Hope that helps.

Trevor

2 replies

Vamitul
Legend
May 8, 2013

Hurix, change your find as to find only chars at the end of the paragraph like this:

app.findGrepPreferences.findWhat=".+$";

app.findGrepPreferences.appliedCharacterStyle="Italic";

then just instert the em_space at the index 0 of the found text:

myFind.insertionPoints[0].contents=SpecialCharacters.EM_SPACE;

Jump_Over
Legend
May 8, 2013

Hi,

Is it what you need?

myFind.insertionPoints[-2].contents  =  SpecialCharacters.EM_SPACE;

Jarek

hurix
hurixAuthor
Inspiring
May 8, 2013

Hi,

Thanks for your reply.

But I need to place before end of the word(Italic).

above script is place end of the paragraph.

hurix

Jump_Over
Legend
May 8, 2013

Hi,

I see...

What about this:

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat  = "(\\<.+\\>)\\s*$";

app.findGrepPreferences.appliedCharacterStyle = "italic";

app.changeGrepPreferences.changeTo =  "~m\$1";

myDoc.changeGrep();

if your goal is the last word not preceded by any space replace this line;

app.findGrepPreferences.findWhat  = "(?<!\\s)(\\<.+\\>)$";

rgds

Jarek