Skip to main content
Participant
December 20, 2022
Answered

Grep expression to convert written out numbers to actual numbers

  • December 20, 2022
  • 3 replies
  • 618 views

Hi all!

I'm working on a cookbook and need to search the ingredients sections, search for the first word and if it's written out, like twelve, convert it to the number 12. I'm adding the expression to the FindChangeList.txt file so that I can use the FindChangeByList.jsx script. 

Right now, I'm at:

 

grep {findWhat:"^(Twelve)", appliedParagraphStyle:"ingredients"} {changeTo:"12"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

 

Do I need to copy and paste that line for every number? Should I made a csv and do a find a replace based off that? Is there any better way to tackle this? 

This topic has been closed for replies.
Correct answer pixxxelschubser

OK. That's strange. I can't find a download link either.

But I'm very sure you can adapt this:

https://indesign.hilfdirselbst.ch/2009/05/monatsnamen-bei-datumsangaben-in-zahlen-wandeln.html

(The script there converts the name of the month into numbers in dates, such as 12. September 2008, and at the same time inserts 1/8th intervals after the dots. Result --> 12. 9. 2008)

3 replies

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
December 21, 2022

OK. That's strange. I can't find a download link either.

But I'm very sure you can adapt this:

https://indesign.hilfdirselbst.ch/2009/05/monatsnamen-bei-datumsangaben-in-zahlen-wandeln.html

(The script there converts the name of the month into numbers in dates, such as 12. September 2008, and at the same time inserts 1/8th intervals after the dots. Result --> 12. 9. 2008)

Participant
December 22, 2022

Oh! I can totally use this, thank you!!!

pixxxelschubser
Community Expert
Community Expert
December 22, 2022
quote

Oh! I can totally use this, thank you!!!


By @KellyMSmith1016

 

I know.

😄

 

  1. change the words
  2. change the Grep
  3. run the script
  4. ready.

😉

James Gifford—NitroPress
Legend
December 21, 2022

Honestly... this would seem to be a one-time job for a series of find-and-replaces. Search for [paragraph return][number word] and replace. You could even restrict it to the style used for ingredients, if that would be helpful.

 

You could be done with "one" through "twenty" in less than a half hour... far less time and effort than finding, writing, adapting and debugging a script you may never need again.

 

pixxxelschubser
Community Expert
Community Expert
December 21, 2022
quote

Honestly... this would seem to be a one-time job for a series of find-and-replaces. Search for [paragraph return][number word] and replace. You could even restrict it to the style used for ingredients, if that would be helpful.

 

You could be done with "one" through "twenty" in less than a half hour... far less time and effort than finding, writing, adapting and debugging a script you may never need again.

 


By @James Gifford—NitroPress

 

You are right there, of course.

 

But in principle it is certainly interesting to see how one can quickly create a functioning script from a "blueprint" (also for similar tasks in the future). And since such scripts already exist - why not?

 

The other way is similarly fast: Save your individual grep queries and apply the ingenious script ChainGrep.jsx from Gregor Fellenz




James Gifford—NitroPress
Legend
December 21, 2022

I believe in getting a task done, not spending 3X as much time inventing a way to make it "faster." 🙂

 

Like most of the tasks for which a script is recommended as a solution, there will need to be painstaking proofreading of the result even after "getting it working" and a few trial runs.

 

Using Find-and-Replace combines semi-automation, editorial judgment and proofing/review all in one pass. And the task would likely have been completed in the time frame since the OP's first inquiry.

 

But by all means, if the tool exists, it must exist to be used. 😛

 

ETA: Lest that sound too harsh, I think we're talking about a spectrum of tasks here. When it's purely layout, style or hard-content changes, GREP and scripts are fantastic tools. Change every instance of a word in context, make sure all sentences are capitalized, replace one set of values with another... great uses.

 

But if you back up to writing/editorial/content development, which I see the above inquiry to fall within, no amount of script wizardry replaces intelligence and judgment. That task can be scripted, yes, with enough work... but I sure wouldn't send the doc off to publication without very close proofing to make sure some unexpected combination of words in other places weren't changed. Or that it got every instance because in one place, it was "Tow cups flour" instead of "Two."

 

I think — in all good humor — that the highly technical, design, layout, app experts here sometimes overlook that there is often content involved that isn't subject to even the most elegant automated processing. Or that all the time needed for proofing "ain't their job."

 

As a writer, editor, publisher, publication designer AND dab hand with ID... I can see the distinctions in these tasks.

 

pixxxelschubser
Community Expert
Community Expert
December 20, 2022

There are two German scripts that do the opposite: "Zahlen-zu-Text-Prepare.jsx" und "Zahlen-zu-Text-Replace.jsx" on https://www.indesignscript.de/indesigntipps/

That could be a good starting point?

Participant
December 21, 2022

That would be a great place to get started! However, I don't seem to be able to download or purchase that particular script from that site.