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

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

Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

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

TOPICS
How to , Type

Views

1.0K

Translate

Translate

Report

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 1 Correct answer

Community Expert , May 28, 2022 May 28, 2022
(?<=\d)(st|nd|rd|th)\>

Votes

Translate

Translate
Community Expert ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Try the following

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

-Manan

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

This finds no match ... 

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Did you spcify a Character Style?

How? Show us the character settings.

Show us the GREP PANEL inside the paragraph style.

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

This should work

 

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

 

(it also includes “st” for 1st)

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Add \> to the GREP

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

EDIT: sorry, it works.

I was adding spaces between brackets and afterward. Ignore following paragraph. 

=====

This is also finding no match.

Attached is the screenshot of what I am doing, which should reply also to your comment above.

I am doing "Find Next" not yet "Change"

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

  1. You added a space between ) and \. Remove it.
  2. Why do you use Find & Replace? Make the GREP part of the Paragraph Style.

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

2. Because I am a beginner 🙂 

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Could you please explain how this is working?

I understand the (st|nd|rd|th) part where | is the bitwise OR operator.

\d is "any digit", but what about the rest? 

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Positive Lookbehind

Formula
End of Word

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

@Inélsòre 

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

If my query finds “1910 they”, it is because there is no space between “1910” and “they”. Otherwise, it only finds “th”, “st”, “rd” and “nd” when there is a digit before but not if there is a space before.

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

Willi's answer added "end of word". 

Do not know what your formula was missing.

Screenshot with hidden characters

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

This help shall not help for a concrete situation. It shoul show you how to do it, Look into the bread crumbs behind the @-menu in the dialog.
For that purpose not find & replace is the best solution, use GREP as part of the Paragraph Style.

 

What do you want to say with your screenshot?

Votes

Translate

Translate

Report

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
Enthusiast ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

@jmlevy said that if his formula was not working it was because there was no space between 1910 and they.

I showed there was an ordinary space in the screenshot.

Votes

Translate

Translate

Report

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 28, 2022 May 28, 2022

Copy link to clipboard

Copied

LATEST

It should work, when a \> is put at the end, that means when it is at a word’s end. 

Votes

Translate

Translate

Report

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