Quick GREP To Superscript Ordinals
Need to format all your ordinals (such as "1st" and "2nd") properly? This easy GREP expression should do the trick!
M.V. wrote:
I have some numbers with ordinals (21st, 54th, 2nd etc.). I would like to search and replace by GREP all of those “st”, “nd”, “rd” and “th” and change their format to OpenType superscript.
You are absolutely correct that this is a great case for GREP! Fortunately, it’s not hard to do. First you need to write an “or” expression: (st|nd|rd|th). Those are vertical bars (also called a pipe) between each string you’re looking for. Next, make sure they’re the last thing in the word by putting a \> (backslash greater than) after it. Finally, you only want to find those strings when there’s a number (digit) before them, right? So add a “positive lookbehind” at the beginning:Â (?<=\d). When you’re done, the full grep code is:
(?<=\d)(th|st|nd|rd)\>
You can use that in the GREP tab of the Find/Change dialog box, or as the basis of a GREP Style (in CS4). Just apply a character style setting the found text to superscript.

One note, however: If you’re using an OpenType font, you may be tempted to use the OpenType Superior/Superscript feature (in the Position pop-up menu, in the Basic Character Formats pane of the Character Style Options dialog box). Sounds great, but it may not work. Why? Because some OpenType fonts don’t support that style. For example Myriad Pro — shown on the first line in the image above — doesn’t do squat with normal English ordinals. (It only works with “o” and “a”). However, Minion Pro and Chaparral Pro both (also shown above) work great.
Want more GREP tips? Check out Erica’s GREP course here!
This article was last modified on June 16, 2023
This article was first published on April 30, 2009
Commenting is easier and faster when you're logged in!
Recommended for you
Relink from One Image File Type to Another
Need to relink all your TIF images to PSD (or JPG to PDF, or whatever)? CS4's Li...
Formatting Important Phrases in InDesign with GREP
In the past, I have worked with clients to build catalogs where the phrase...
InDesign GREP You Already Have
There are a few things in InDesign that send the most seasoned of designers scre...
