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

Grep alternate method

Contributor ,
Dec 05, 2019 Dec 05, 2019

Hi,

While using the grep in coding, the character style is applied additionally within the word, please suggest an alternative method if any.

 

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=-)([[:word:]]+)";
app.changeGrepPreferences.changeTo = "~-~k$0";
app.documents.item(0).changeGrep();

 

Original (see color text):

Screen Shot 2019-12-05 at 3.16.29 pm.png

 

After executing the code (see color text):

Screen Shot 2019-12-05 at 3.26.39 pm.png

 

Thanks,

Selva

TOPICS
Scripting
2.9K
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

correct answers 1 Correct answer

Community Expert , Dec 05, 2019 Dec 05, 2019

I missed something in your original post. So the character style is applied but you don't want that, correct? The character style is probably already there. What is that red 3 doing there? Is that a footnote or endnote with a style applied? Well, I still can't reproduce it. What else is there? Can you show a screenshot of the story editor?

 

Here's another formulation to try:

Find what: -(?=\w)

Change to: -~-~~k

 

Translate
Community Expert ,
Dec 05, 2019 Dec 05, 2019

Works ok here. Which InDesign version do you use? Maybe try a different formulation, e.g.

\K(\w+)

which means the same as your expression.

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
Contributor ,
Dec 05, 2019 Dec 05, 2019

Hi Kahrel,

Thank you so much for the quick response. I have used CC2019 (14.0.3) and the CC2017 (12.1.0.56). I will try the suggested method and get back to you shortly.

 

 

 

Thanks,

Selva

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
Contributor ,
Dec 05, 2019 Dec 05, 2019

Hi Kahrel,

Related with this testing, when I'm using the manual grep replace method with one by one, it's working fine (see below 1st screenshot). But I have used the 'Change All' option manually, it's going wrong (see 2nd screenshot). The same concept is working in coding itself. So, can I consider this for InDesign default behavior and no need to change the coding? Please guide me if I'm wrong.

 

Screen Shot 2019-12-05 at 4.24.49 pm.png

 

Change All:

Screen Shot 2019-12-05 at 4.29.46 pm.png

 

 

Thanks,

Selva

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
Community Expert ,
Dec 05, 2019 Dec 05, 2019

I missed something in your original post. So the character style is applied but you don't want that, correct? The character style is probably already there. What is that red 3 doing there? Is that a footnote or endnote with a style applied? Well, I still can't reproduce it. What else is there? Can you show a screenshot of the story editor?

 

Here's another formulation to try:

Find what: -(?=\w)

Change to: -~-~~k

 

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
Contributor ,
Dec 05, 2019 Dec 05, 2019

Hi Kaherl,

Thanks for focus on this topic. The character style is applied to one character in originally, but I don't want to modify anything here, just I try to insert the break character before the word. Below my reply with 'Ans:'.

 

  1. So the character style is applied but you don't want that, correct? Ans: Yes, but I need to maintain the same (no need to change anything here).
  2. The character style is probably already there. What is that red 3 doing there? Ans: This is a reference number, color is applied with a character style.
  3. Is that a footnote or endnote with a style applied? Ans: Yes.
  4. Well, I still can't reproduce it. What else is there? Ans: While inserting the non-printable character (no-breaking) with 'grep change all ', The Character style is applied to text too (before one character in every insertion count).
  5. Can you show a screenshot of the story editor? Ans: Screen Shot 2019-12-05 at 5.32.07 pm.png

 

Your suggestion is working fine with small changes, reference here:

---

app.findGrepPreferences.findWhat = "-(?=\\w)";
app.changeGrepPreferences.changeTo = "$0~-~k";
app.documents.item(0).changeGrep();

---

 

Kindly let me know if not clear.

 

Thanks,

Selva

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
Contributor ,
Dec 05, 2019 Dec 05, 2019

Hi Kaherl,

 

Kindly suggest to alternate this code too,

 

app.findGrepPreferences.findWhat = "[[:word:]]+(?=-)";
app.changeGrepPreferences.changeTo = "~-$0";
app.documents.item(0).changeGrep();

 

 

 

Thanks,

Selva

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
Contributor ,
Dec 13, 2019 Dec 13, 2019
LATEST

 app.findGrepPreferences.findWhat = " (?=\\w+-)";
app.changeGrepPreferences.changeTo = "$0~-";
app.documents.item(0).changeGrep();

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