is now part of CreativePro.com!

Convert Text to Lowercase with a GREP Utility

23

As I mentioned back in this earlier post, InDesign’s GREP feature lacks the ability to convert found text from upper to lower case (or vice versa). In the comments to that post, jezabellabingbong wrote:

I have 300 pages that I want to change the first character of a bullet point to lowercase. It would also be nice to remove the full stop at the end of the bullet point. As some bullet points contain several sentences, it would need to omit the full stops and capitalised sentences within the paragraphs.

So today the answer remains: No, you can’t do this in InDesign. But InDesign just uses one flavor of GREP. There are others, including some that can convert case. So think outside the box!

Here’s my original text, formatted with automatic bullets (using a paragraph style called List):

Note that some paragraphs end with a period and others don’t. We want to make all the characters at the beginning of the list items lower case and remove the period when present.

The trick is to export your text in a file format that can be manipulated by GREP (text only) while also being able to re-import it without losing all your formatting. The answer, of course, is InDesign Tagged Text. So choose File > Export, then choose InDesign Tagged Text from the Format pop-up menu. Now open that text file in a text editor that has a GREP feature. On the Mac that should probably be BBEdit or its free (but very powerful little sister) TextWrangler:

All the paragraphs are tagged with the paragraph styles, so it’s easy to search for paragraphs that start with our “list” style. Now we open the Find/Change dialog box, turn on the GREP checkbox, and type in some code. Warning: There are likely more elegant and optimized ways to write the GREP codes; feel free to note your favorite ways of doing this in the comments below.

In this case, I’ve written GREP code

(<ParaStyle:list>)([A-Z])(.+)([a-z])\.?$

which searches for any string of text that starts with the “list” paragraph style tag, followed by a single uppercase character, followed by any string of text, ending with any lowercase character that may or may not be followed by a period at the end of the paragraph.

I replace it with the original paragraph style codes (\1), then use the \l code that converts the following character to lowercase, then insert the rest of the line of text (\2\3\4), leaving out the period at the end if one had been there. (Note that TextWrangler is using backslash-number instead of the dollarsign-number code that InDesign uses. This is another example of how different flavors of GREP work slightly differently. Be sure to read the Help files for whatever program you’re using!)

When I click Change All, it does it’s magic. The only problem is that I’ve removed the periods at the end of the bullet items that needed them (the ones that contain a second sentence in the line. So I’ll run a second GREP query to add those periods back in:

Seems like there must be a way to do both these steps with one GREP query (basically, make the first one leave in the punctuation for those paragraphs that need it), but my Monday-morning brain isn’t finding one.

Anyway, the important thing is that after I’m done, I just need to save the text file, go back to InDesign, delete the text that was there, and use File > Place to import the modified tagged text back in. The result looks exactly the same as the original, except for the changes we made:

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Harry Brindley says:

    David: Great idea, integrating InDesign and BBEdit. Bare Bones’ BBEdit has long been the engine behind many of my scripted solution to text processing problems. Appended is a bookmark to a BBEdit Grep Tutorial I’ve found handy — as old as it is. Harry

    https://www.anybrowser.org/bbedit/grep.shtml

  • Peter Kahrel says:

    A simple script does the trick:

    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.appliedParagraphStyle = "List";

    // First letter in bullet list to lower case:
    app.findGrepPreferences.findWhat = "^.";
    found = app.activeDocument.findGrep();
    for (i = 0; i < found.length; i++)
      found[i].characters[0].changecase (ChangecaseMode.lowercase);

    // Delete final period
    app.findGrepPreferences.findWhat = ".$";
    app.changeGrepPreferences.changeTo = "";
    app.activeDocument.changeGrep();

    Removing periods at the end of paragraphs can be done in the interface: the script here simply automates that: Find .$ and replace with nothing (there should be a backslash before the period, two of them in the script text, but they disappear all the time, and time is running out).

    Peter

  • Wow… Thanks, Peter! I hate it when a simple script makes an entire blog post moot. ;)

    If anyone tries to use that script, make sure you set the curly quotes to straight quotes and change “List” to the name of your paragraph style.

    This code won’t put the quotes back on for the list items that have full sentences, but I bet that wouldn’t be hard.

  • Peter Kahrel says:

    “This code won?t put the quotes back on for the list items that have full sentences, but I bet that wouldn?t be hard.”

    Probably not — but you didn’t mention them ;)

    P.

  • Oh! Sorry… I typed “quotes” where I meant periods/dots. No problem.

  • Jeremy says:

    Like all Peter’s scripts, this is an object-lesson in elegance and sparse beauty. It can also be adjusted in reasonably obvious ways to suit individual needs.

    Peter’s introduction to scripting ( ‘Scripting InDesign with JavaScript’) is brilliant, and I recommend it to everyone who wants to take InDesign to new levels.

  • Peter Kahrel says:

    Thanks for your kind words, Jeremy. By the way the update of ?Scripting InDesign with JavaScript? to CS3/4 will be out any day now.

  • Eugene says:

    Are adobe listening though. Why no record actions button?

    Seriously – the scripts posted in the last few weeks have been nothing short of miraculous.

    Well done guys.

  • Jeremy says:

    Why no record actions button?

    Well, just thinking aloud?

    The difference between an action and a script is a bit like the difference between a dance instructor and a puppeteer.

    With an action, you make the “moves” you want the program to make, then you tell it to do the same thing on its own. It has to recognize which “moves” are relevant. With a script, you “pull the strings” of the program in such a way that it has no choice over what to do, so it doesn’t have to “recognize” what’s relevant and what isn’t.

    If you change a capital ‘A’ to a lower case ‘a’, and tell the program to “do that again, on your own this time”, it has to “recognize” the relevant thing you did, so it can imitate it. But was the relevant thing you did the replacement of a capital letter with the same letter in lower case, or was it the replacement of any old character with an ‘a’?

    My tentative guess is that recording actions in InDesign would call for so much “recognition” on the part of the program that it would be much more difficult to arrange than in Photoshop (say). So it probably isn’t an oversight so much as a practical impossibility.

  • @Jeremy: I see what you mean, but I don’t think it’s that hard. I mean, just give us a combination of the “do again” features in Illustrator and MS Word. Replacing an “A” with an “a” is literally just a “type the letter a” command, so doing it over would type another letter “a”.

    My understanding is that doing Actions would be a huge, huge engineering effort on Adobe’s part. However, perhaps doing a “Do it Again” feature might be more doable.

  • Jochen Uebel says:

    @ David:
    “I hate it when a simple script makes an entire blog post moot.”
    You should not. Peters Script is excellent, sure. But how many people are able to program scripts? To learn a bit more about GREP (by the help of posts like yours) could be a “workaround”. Kind of low level scripting.

  • Uwe Laubender says:

    But of course you have to consider another thing if you change capitalcase to lowercase: there might be names at the beginning of a paragraph. How would you exclude them from changing? Especially when you run into acronyms.

  • @Jochen: I was just joking with that comment. I think it is important to know how to do this with different methods — a script, GREP, and so on.

    @Uwe: You bring up a good point! Wow, that complicates things a lot. Unless you have a list of all the possible acronyms and names, you would probably just have to go back and proof the document for those kinds of errors.

  • Nadya Miloserdova says:

    At least there are only 26 letters in English ABC. So far, the following routine is coming to mind:
    Find what (GREP): ^A
    ParaGraph style: List
    Change To: ^a
    Save the query. Give it a descriptive simple name, like “A-01”.
    Do the same for other 25 letters.

    Next time simply run 26 automatic queries saved in the memory.

    Or perhaps use the Creative Suite inherent FindChangeBy List script.

    This seems to be an alternative to scripts or BBedit grep search.

  • Lindy M says:

    If you don’t mind using All Caps, I’ve made this simple routine work on test text.

    First, protect any acronyms and proper nouns with All Caps (possibly using a character style that can be replaced later). Acronyms are easy to find/change using GREP, but if there were many proper nouns this method could be more trouble than it’s worth.

    Select the list and change it all to lower case manually. Anything already formatted with All Caps isn’t affected by the change to lower case.

    Then GREP search for single character following end-of-sentence punctuation + space.

    Change the found character format to All Caps.

    If it were a long and complex list you might have to factor in quotation marks, parentheses and so on, but that’d be possible to achieve fairly simply, I’d think, using unicode class properties.

    Of course, I’m a GREP dunderhead and have probably missed something obvious. However, for the simple task set by the OP (and ignoring for the moment the preference for full stop handling), this appears to work.

  • Carlie says:

    I have been looking for the solution to the exact problem that Jezabellabingbong was.

    Thanks David, I have been searching my Grep books for the solution – so glad to know the reason I didn’t find the answer was because it doesn’t exist in InDesign GREP

    I used your Text Wrangler method to test out if this worked. Few things I noticed – not sure if is the same for everyone.

    ? Will not affect Paragraph styles that have any overrides (including manual kerning)
    ? I cant get the text to change for any Paragraph style that is in a Style Group (any folder in Styles Panel)
    ? Does not work with a character style applied to the text. But this can work to an advantage. Can use this to make sure important names/words never change. I tried adding the character style to the code – but it causes an error.

    I am not sure if for the Character Style and Style Group if i am entering the code incorrectly or if it is just too complex.

    Thanks

  • The script on this page is another very good option for changing case based on GREP.

  • jezabellabingbong says:

    Hi David, just a quick note to say thank you! Had forgotten I posted that query and only found it after searching for another solution to something else. Will try to implement your elegant solutions over the next month and report back.

    Here?s another conumdrum fro you?

    As indesigns footnotes features are primitive to say the least, we are forced to convert all footnotes to text to run them over two columns at the bottom of the page (I use convert to endnotes script to help). We try and do that as late as possible, but Sod?s law the client will come back and insert a few more, thereby messing up the numbering. I would like to run a script that searches from a chosen point to the end of the document and changes the footnote reference number both in the copy and in the footnotes themselves by a specified amount. Having 150 footnotes to manually adjust is ….. hmmm, best not print that!

  • You might take a look at this page for a script that lets you increase numbering based on various properties. Perhaps that would work: https://creativepro.com/free-script-to-change-all-numbers-in-a-document-using-math.php

  • jezabellabingbong says:

    Wow, that was a fast reply! Will give it a try. Thank you again. Despite a love of all things automated my brain turns to mush whenever I try and remember how to compose a GREP.

  • travel says:

    I don’t know whether it’s just me or if everyone else encountering problems with
    your website. It appears as if some of the written text on your posts are running off the
    screen. Can someone else please provide feedback and let me know if
    this is happening to them too? This may be a issue with my browser because I’ve had this happen before.
    Kudos

    • Tammy says:

      Hi travel,

      Thinking it might be on your end. I’m using Chrome on my desktop and the text is responsive. Checked it in Safari on my phone and it is okay there too. What browser and device are you using and experiencing the problem?

  • deposaja.com says:

    Thank you a lot for sharing this with all folks you really understand what
    you’re speaking approximately! Bookmarked. Kindly also consult with my web site =).

    We may have a link exchange agreement between us

  • >