Skip to main content
Inspiring
May 28, 2022
Answered

GREP: how to find "th" "rd" "nd" after a number?

  • May 28, 2022
  • 2 replies
  • 3375 views

I need to filter all the "th" "rd" "nd" after a number in a story to apply the Superscript character style to them. 

I tried "\n" (any number) followed by "th" (all without quotes), but it didn't work.

Tried separating them with commas "\n,th" or with braces, brackets [\n]th {\n}th but no luck.

What am I missing here? 

Could you also suggest a handbook for GREP?

Thank you

Correct answer Willi Adelberger

Add \> to the GREP


(?<=\d)(st|nd|rd|th)\>

2 replies

jmlevy
Community Expert
Community Expert
May 28, 2022

This should work

 

(?<=\d)(st|nd|rd|th)

 

(it also includes “st” for 1st)

Inspiring
May 28, 2022

This is better but it also finds me the instance "1910 they" because there is a number before th.

Could we refine this so that there is no space between the number and the letters?

Willi Adelberger
Community Expert
Community Expert
May 28, 2022

Add \> to the GREP

Community Expert
May 28, 2022

Try the following

(?<=\d)(?:th|rd|nd)

-Manan

-Manan
Inspiring
May 28, 2022

This finds no match ... 

Willi Adelberger
Community Expert
Community Expert
May 28, 2022

Did you spcify a Character Style?

How? Show us the character settings.

Show us the GREP PANEL inside the paragraph style.