Skip to main content
Inspiring
November 4, 2022
Answered

Find and Change formatted of repeated text using GREP

  • November 4, 2022
  • 4 replies
  • 715 views

Hi everyone,

Can anyone help me with a GREP find/change? I'm using the code "\b(\w+)\s+\1\b" to find repeated (duplicate) words in a document and I was wondering if it's possible to change the formatting of the duplications only? For example:

Email subject 1:Email subject 1:

I would like to change the Character Style format of  the repeated text "Email subject 1:" and keep the first instance "Email subject 1:" as it is.

Thanks in advance,
Rogerio 

This topic has been closed for replies.
Correct answer pixxxelschubser

You can try:

find:

([\S\s]+)\K\1

replace with:

[nothing] --> let this field empty

 

replace style:

[your character style] --> e.g. Character Style 2

4 replies

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
November 4, 2022

You can try:

find:

([\S\s]+)\K\1

replace with:

[nothing] --> let this field empty

 

replace style:

[your character style] --> e.g. Character Style 2

Inspiring
November 7, 2022

It worked just as expected! Thank you so much 🙂

pixxxelschubser
Community Expert
Community Expert
November 4, 2022

Thank you very much for your sample file.


Please give us several concrete examples and answer my questions and additionally: Does your grep question only refer to the subject line or also to the "reference-frame"?

Community Expert
November 4, 2022

Thanks for following up

pixxxelschubser
Community Expert
Community Expert
November 4, 2022

Please give us two three concrete examples.

Two important counter-questions:

  1. Is there really no space between the two repetitions?
  2. Is there always one (or more) digit(s) and always a colon?
Community Expert
November 4, 2022

Based on your example I have come up with this

(\w+\H.+?[[:punct:]])\K\1

 

However, I'd need a bigger sample set to get it more accurate for you.

Inspiring
November 4, 2022

Hi Eugene,

Thanks for getting back to me! 🙂

I have attached a sample indd so you give it a shoot.

Regards,
Rogerio

Community Expert
November 4, 2022

If that's all it is - then it works for this case. Give it a try and let me know if it is failing.

It does catch the Global Template text in the pink box too though...