A Script to Find Spelled Out Numbers in InDesign
Need to check a document for improperly spelled out numbers? This script does all the heavy lifting.

A friend called me with what I thought was a simple request: find a way to search in an InDesign document for numbers that are spelled out, like one thousand forty-seven and twelve hundred six. “No problem,” I said naively, and whipped up a simple GREP search expression that he could enter in InDesign’s GREP Find/Change dialog box, thinking that would be the end of it. Instead, I soon discovered that this was a much harder nut to crack, and I began a long journey to try to find a complete answer to the problem. First, a bit of background. In most technical, scientific, and other long, complex documents, common editorial convention is to spell out numbers less than 10, except for fractions and decimals. There is some slight variation on this practice, depending on audience, country, and other variables. For more details, see this article at Wikipedia and this one at Grammarly.com. The problem faced by my friend was several hundred pages of text where the authors had spelled out numbers greater than ten, and he faced the daunting challenge of reading through the text to locate these and replace them with numerals (changing two thousand four hundred twenty-two to 2422, for instance). This turns out to be a much more complex issue than it first appears, and for some reason, like a dog with a bone, I couldn’t let it go. The problem is that the English language is highly irregular when it comes to how we spell out numbers, with lots of exceptions. Here are just a few examples:
- 21 might be written as twenty one or twenty-one
- 1202 might be written as one thousand two, one thousand and two, twelve hundred-two, or twelve-hundred and two.
- Years are expressed
differently than numerals, such as seventeen seventy-six or twenty twenty one.
Then, to make this even more challenging, I thought it would be helpful if we could also search for the numerals 0–9 when they aren’t spelled out, because they usually should be, except when…
- In fractions, such as ¾, ½, etc.
- In decimal fractions, such as .7 or 2
- Before a comma followed by another numeral, like 1,234
And for good measure I decided we also need to search for 1st, 2nd, 3rd, etc. because those should be replaced with first, second, third, and so on. Each case that I describe above poses a particular problem in GREP. But if you’ve ever written a GREP expression, you know that the tiny Find What field in InDesign’s GREP Find/Change dialog box is ridiculously small (Figure 1). And, the GREP expression I was creating was quickly becoming huge.

Figure 1. The tiny Find What field in the GREP Find/Change dialog makes entering and editing complex GREP expressions very difficult. There’s got to be a better way!

Figure 2. Peter Kahrel’s GREP editor script makes typing long GREP strings much easier. You can even include space, returns, and comments to make your GREP string more clear. This usually works very well, but the length of the GREP expression I was writing pushed it over the edge.

Figure 3. A screenshot of a portion of the script that breaks the very long GREP string up into eight smaller parts.

Figure 4. The final GREP expression. Much too long to edit in the Find/Change dialog!
Commenting is easier and faster when you're logged in!
Leave a Reply
Recommended for you

Illustrator Downloadable: Tropical Shadow Overlay Kit
[memb_has_any_tag not=not tagid="282,643,655,657,1664"] Downloadables are an exc...

Illustrator Downloadable: Summer Citrus Pattern Set
Downloadables are an exclusive benefit for CreativePro members! (Not a member ye...

InDesign Downloadable: Tables SuperGuide
Downloadables are an exclusive benefit for CreativePro members! (Not a member ye...
Ironically, I actually need the opposite – my employer has a policy that numbers 10 and under, when not in a table, mathematical expression, or address, need to be spelled out. That should be a bit simpler. :)
Like a shiny new Apple product, sometimes you don’t NEED a thing, but it’s so beautiful you just WANT the thing. I’m going to download this, and pet it, and love it, and maybe someday I’ll even USE it. Thanks, Keith… amazing work (as usual)!
Awesome stuff, Keith! It’s weird how a friend asking for help can start you down an epic rabbit hole, isn’t it? There are those subtle moments along the way when curiosity turns into determination, determination into stubbornness, stubbornness into obsession (in my case, usually around 2 am). Like all good adventures, these micro-project-turned-saga things tend to be more enjoyable as stories than while they’re in progress!