Skip to main content
New Participant
February 11, 2025
Answered

How to use GREP to select specific in bracket words?

  • February 11, 2025
  • 2 replies
  • 581 views

I am currently using this GREP to select when there are certain words+Numbers or other characters in brackets.

(\(|\[)(Bild|Fig|Pos|Item|Pic|Photo|Abb)\s*\.*\d*\+*\d*\.*\s*~e*(\)|\])

 

This expression isn't ideal because it won't work if there are numbers and plus symbols one after another multiple times (as seen in the screenshot below).

Is there a GREP expression that finds open bracket + Word and then selects everything until it finds a closed bracket?

Correct answer Peter Kahrel

The simplest would be to look for ([word] up to the next closing parenthesis:

 

 

[(\[]((Bild|Fig|Pos|AbbItem|Pic|Photo)\.?).+?[)\]]

 

But if you want to match numbers and maybe +, then use this:

 

[(\]]((Bild|Fig|Pos|AbbItem|Pic|Photo)\.?)[\d\+]+[)\]]

 

 

2 replies

Peter KahrelCorrect answer
Community Expert
February 11, 2025

The simplest would be to look for ([word] up to the next closing parenthesis:

 

 

[(\[]((Bild|Fig|Pos|AbbItem|Pic|Photo)\.?).+?[)\]]

 

But if you want to match numbers and maybe +, then use this:

 

[(\]]((Bild|Fig|Pos|AbbItem|Pic|Photo)\.?)[\d\+]+[)\]]

 

 

New Participant
February 12, 2025

Thank you!
This solved my problems.

Robert at ID-Tasker
Brainiac
February 11, 2025

I'm not a GREP expert - but until someone better than me will chime in - you could take your "numbers" part in brackets and add "+" afterwards - it will tell InDesign to look for multiple occurrences: 

 

(\s*\.*\d*\+*\d*\.*\s*~e*)+

 

Or it should be possible to shorten it to ".+" but as GREP in InDesign is "greedy" - "?" need to be added in the right place - but I'm not good at it and I'm replying from my phone.