Skip to main content
Participant
November 12, 2022
Answered

Exclude certain letter associations from a GREP style

  • November 12, 2022
  • 2 replies
  • 613 views

Hello community, I would like some advice on how to use grep in a file I am designing. I must admit that I don't understand this language very well. I currently have a paragraph style applied to several texts, I would like some words to be in bold automatically thanks to the use of grep and a character style. I can do it so far, but it gets complicated for me when the example below comes up.

 

For example, one of the words I need to highlight is "prépa" but sometimes the word "préparation" is also affected by the grep. What is the syntax to exclude the application of the character style on the beginning of the word?

 

Thank you in advance for your possible answer

Peter 

 

This topic has been closed for replies.
Correct answer pierrem3657468

Manty thanks @Scott Falkner ! This works very well even if the proposal of @pixxxelschubser  is a bit more complete! 

2 replies

pixxxelschubser
Community Expert
Community Expert
November 12, 2022

Hi @Scott Falkner 

I would prefer a similar but even more restrictive variant. Because your greps also find "someletterprépa" (false positive hit), for example.

 

I tried

search for:

\b[Pp]répa\b

 

Or like this - if everything should also be possible in capital letters.

search for:

(?i)\bprépa\b

 

Robert at ID-Tasker
Legend
November 12, 2022

Exactly, \b (word boundary) is much better.

 

Scott Falkner
Community Expert
Community Expert
November 13, 2022

TIL word boundary. Nice.

Scott Falkner
Community Expert
Community Expert
November 12, 2022

Try this: (?i)prépa(?=\s|\(|\.)

It begins by turning on case insensitivity, which is why it can apply the style to the first word. After that it uses positive look ahead to make sure it applies only if there is white space, a closing parenthesis, or a period following the word.

 

On second thought, this might work better: (?i)prépa(?![\l\u])

This uses negative look ahead to disqualify any matching expression followed by any letter.

 

pierrem3657468AuthorCorrect answer
Participant
November 13, 2022

Manty thanks @Scott Falkner ! This works very well even if the proposal of @pixxxelschubser  is a bit more complete!