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

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

Explorer ,
May 22, 2025 May 22, 2025

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!

TOPICS
How to
971
Translate
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 4 Correct answers

LEGEND , May 22, 2025 May 22, 2025

It's not a very "elegant" solution - and I'm pretty sure someone will find a better one - but maybe it be will good enough for you:

 

RobertatIDTasker_0-1747925261242.png

 

You can always add extra inclusions.

 

Translate
Community Expert , May 22, 2025 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.

 

Screenshot 2025-05-22 at 21.29.47.png

 

Screenshot 2025-05-22 at 21.30.24.png

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

 

Translate
Community Expert , May 23, 2025 May 23, 2025

It's much more simple:

[^?]+$

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

Translate
Community Expert , May 23, 2025 May 23, 2025

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.

Translate
LEGEND ,
May 22, 2025 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. 

 

Translate
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
LEGEND ,
May 22, 2025 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. 

 

Translate
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
LEGEND ,
May 22, 2025 May 22, 2025

It's not a very "elegant" solution - and I'm pretty sure someone will find a better one - but maybe it be will good enough for you:

 

RobertatIDTasker_0-1747925261242.png

 

You can always add extra inclusions.

 

Translate
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
Explorer ,
May 22, 2025 May 22, 2025

Thank you! Seems very close. What do the brackets do?

Translate
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
LEGEND ,
May 22, 2025 May 22, 2025
quote

Thank you! Seems very close. What do the brackets do?


By @Micah5C08

 

You're welcome. 

 

Square ones - "any character from the list". 

 

\w - any word character 

\d - any digit 

\s - any white space 

\. - "." 

\: - ":" 

 

Translate
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
Explorer ,
May 22, 2025 May 22, 2025

Ah perfect! Any new symbol I need in the colored answer part I can just add into the brackets! Amazing!

Thank you so much!

Translate
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
LEGEND ,
May 22, 2025 May 22, 2025
quote

Ah perfect! Any new symbol I need in the colored answer part I can just add into the brackets! Amazing!

Thank you so much!


By @Micah5C08

 

Exactly 🙂

 

You're welcome. 

 

Translate
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
LEGEND ,
May 23, 2025 May 23, 2025
LATEST

@Micah5C08

 

I've just sent you a private message - could you please check top-right corner of this website.

 

Translate
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 ,
May 22, 2025 May 22, 2025
(?<=\?(?!.*\?)).+?.+(?=")
Translate
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
LEGEND ,
May 22, 2025 May 22, 2025
quote
(?<=\?(?!.*\?)).+?.+(?=")

 

Unfortunately, it doesn't work?

 

RobertatIDTasker_0-1747936212286.png

 

Translate
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 ,
May 22, 2025 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.

 

Screenshot 2025-05-22 at 21.29.47.png

 

Screenshot 2025-05-22 at 21.30.24.png

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

 

Translate
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
LEGEND ,
May 23, 2025 May 23, 2025

I've typed it manually - not copy&pasted - unfortunately, still doesn't work:

 

RobertatIDTasker_0-1747989514694.png

 

Translate
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 ,
May 23, 2025 May 23, 2025

Don't know why you can't get it to work - it works. 

Translate
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 ,
May 23, 2025 May 23, 2025

It's much more simple:

[^?]+$

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

Translate
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
LEGEND ,
May 23, 2025 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  "^" 😞

 

Translate
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 ,
May 23, 2025 May 23, 2025

So this is odd @Peter Kahrel what have I done incorrectly?

 

Screenshot 2025-05-23 at 10.42.30.png

 

edit it's catching the " at the end 

 

 

Translate
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 ,
May 23, 2025 May 23, 2025

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.

Translate
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
LEGEND ,
May 23, 2025 May 23, 2025
quote

I hadn't spotted that the closing " should be excluded. [...] 


By @Peter Kahrel

 

There are no closing - nor opening - ("). 

 

OP used them to show/mark quoted text. 

 

Translate
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 ,
May 23, 2025 May 23, 2025

We don't know that - it could be enclosed in quotes. 

That's the sample text provided - that's what I was using to find the text. 

 

Translate
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 ,
May 23, 2025 May 23, 2025

I guess why it's not working for us - using different sample text... 

 

I guess the OP has many ways and options now.

 

We all get a cookie.

Translate
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 ,
May 23, 2025 May 23, 2025

Ah yes - that's great - I might be overthinking it as usual - perhaps the quotes are not part of the search at all.

Thanks

Translate
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