Skip to main content
Inspiring
May 22, 2025
Answered

Grep Styles Help. Apply to style after last question mark only.

  • May 22, 2025
  • 3 replies
  • 1633 views

I have a paragraph that asks several questions. After the last question I want the GREP style to apply to give the answer to the questions a different color to get this result.

"Where was it? When did it happen? At the market at 5:00 p.m."

 

This below works for finding the question mark, but the problem is that it finds every single one.

(?<=\?).+

Giving me this problem.

"Where was it? When did it happen? At the market at 5:00 p.m."

 

Is it possible to find only the last occorance of the question mark?

Thanks!

Correct answer Peter Kahrel

I hadn't spotted that the closing " should be excluded. Itt should be like this:

[^?]+(?="$)

which also fixes the problem of selecting lines that don't contain any question marks.

3 replies

Peter Kahrel
Community Expert
Community Expert
May 23, 2025

It's much more simple:

[^?]+$

 In other words, 'not-question mark to the end of the paragraph'.

Robert at ID-Tasker
Legend
May 23, 2025
quote

It's much more simple:

[^?]+$

 In other words, 'not-question mark to the end of the paragraph'.


By @Peter Kahrel

 

You are Genius 😄

 

I was playing with exclusion - but I was using "!" instead of  "^" 😞

 

Community Expert
May 22, 2025
(?<=\?(?!.*\?)).+?.+(?=")
Robert at ID-Tasker
Legend
May 22, 2025
quote
(?<=\?(?!.*\?)).+?.+(?=")

 

Unfortunately, it doesn't work?

 

 

Community Expert
May 22, 2025

Works for me in 2025 and in 2023

 

Have to admit it didn't work when I copied it from the forum that's for sure. 

It did actually work - something didn't copy right first time - but it does work for me now - oddity with the forum maybe.

 

 

(?<=\?(?!.*\?)).+?.+(?=")

 

Robert at ID-Tasker
Legend
May 22, 2025

I'm replying from my phone so can't check right now: 

 

\?.+$

 

"$" represents end of paragraph. 

 

But it will also style "?" so you still need to play with those look ahead / behind. 

 

I hope it will at least get you on the right track. 

 

Robert at ID-Tasker
Legend
May 22, 2025

Or maybe this will work? 

 

\?\K.+$

 

But InDesign's GREP is greedy - so you might still need to add extra "?" somewhere... 

 

As I've said, I'm on my phone so just brainstorming.