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

GREP - Applying Character Style to whole word

New Here ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

I have a document that has words in a different langauge and those words need to be in a different font. In the word document I've placed they are all in the different font, so when I placed it, I searched for the font and applied a character style to it. To my dismay, at the end of typesetting, I've realized that only a few letters per word have the character style appplied. I have no idea why, maybe something isn't right in the word document, but if possible, I don't want to have to re-place and re-typeset. Is there a way to search for a character style and then apply it to the entire word that it's found in? 

 

 

TOPICS
Scripting , Type

Views

1.4K

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 , Jul 27, 2020 Jul 27, 2020

You can do this in three step... 
First is to mark the text with the character style you need to fix. Let’s call it [ChStyle].

Step 1: Use this to mark the text by adding a # and remove the style
Find: .+ 
Find Format: [ChStyle]
Change: #$0
Change format: [None]

Step 2: Apply the style to entire word
Find: [\l\u]*#[l\u]*
Change: $0
Change format: [ChStyle]

Step 3: Remove the #
Find: #
Find Format: [ChStyle]
Change: empty

Votes

Translate

Translate
Community Expert ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

You can do this in three step... 
First is to mark the text with the character style you need to fix. Let’s call it [ChStyle].

Step 1: Use this to mark the text by adding a # and remove the style
Find: .+ 
Find Format: [ChStyle]
Change: #$0
Change format: [None]

Step 2: Apply the style to entire word
Find: [\l\u]*#[l\u]*
Change: $0
Change format: [ChStyle]

Step 3: Remove the #
Find: #
Find Format: [ChStyle]
Change: empty

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
Enthusiast ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

Hi Jean-Claude, I think there is a typo in the Find expresssion in Step 2. It looks like it should be 

[\l\u]*#[\l\u]*. Perhaps the lowercase l was converted to the numeral 1 accidentally by the forum platform.

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 ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

It was a typo indeed. Edited.

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
Advocate ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

Wouldn't it simply be faster/easier to use InDesign's Find/Change or the Find/Change By List script to search for each word and apply the appropriate character style?

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
Guide ,
Jul 27, 2020 Jul 27, 2020

Copy link to clipboard

Copied

Step 1:
Find: \w+
Find Format: [ChStyle]
Change: #$0

 

Step 2:
Find: (\w*)#(\w*)
Change: $1$2
Change format: [ChStyle]

 

Change \w by [\w-] if you want to target composed words!

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
Guide ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

LATEST

Warning:

 

The guy who indicated here Jean-Claude Tremblay's answer as "correct" is surely someone without a great Grep knowledge!

 

This could obviously mislead this thread readers because my answer is correct too and technically a little more interesting. Not to mention the fact I only use 2 steps and not 3!

 

(^/)  The Jedi

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