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

Find the next word in the paragraph

Community Expert ,
May 01, 2012 May 01, 2012

I have a series of "key words" formatted with a particular Character Style. I am using this to find the words:

var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findTextPreferences = app.findTextPreferences = null;
app.findGrepPreferences.appliedCharacterStyle = "HMI";

var hmiText = app.activeDocument.findGrep();
alert (hmiText.length);

This is working fine. For each found word, I do a look up in an XML file to find its replacement. Then I replace the found word with its replacement. Now I have to do something else that has me stuck. Each word I am replacing has a following word or words in parenthesis. I have to find these and delete them. So, an example would be this:

This is the term (word or words) that I am replacing.

I am finding and replacing "term" with its equivalent from the spreadsheet. But now I have to find "(word or words)" directly following and delete it. When I am done with my find/change, I am usually left with a TextStyleRange or a Word. Given this, I want to find the next word or phrase within parenthesis. Any pointers would be appreciated. Thanks.

Rick Quatro

TOPICS
Scripting
594
Translate
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
Mentor ,
May 01, 2012 May 01, 2012
LATEST

Hi,

If "Each word You are replacing has a following word or words in parenthesis"

then it should be possible to remove all characters using

myStory.characters.nextItem(hmiText.characters[-1])

inside a loop while(myStory.characters.nextItem(hmiText.characters[-1]).contents !== ")" )
first

and do proper find change

after

hopefully...

Translate
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