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!

Bookmark
Please login to bookmark Close

This article was last modified on June 16, 2023

Comments (36)

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading comments...