GREP Solution to Flawed Title Case Feature

Many people don’t realize that InDesign has a Change Case feature in the Type menu (or the Context menu). For example, you can select some text that someone TYPED IN ALL CAPS and change it to lowercase, Title Case (all words are capitalized), or Sentence case (only the first letter in each sentence is capitalized). Unfortunately, while Title Case is great for headlines, it misses the mark because it doesn’t follow a basic rule: that most conjunctions, articles, and prepositions (such as and, but, the, for, a, an, or, and nor) shouldn’t be capitalized.

Fortunately, GREP and Scripting guy Peter Kahrel wrote to us recently with a fun solution he had found to this Title Case problem based on CS3’s GREP searching feature:

  1. Select the text you want to change to Title Case.
  2. Open the Find/Change dialog box (Command/Ctrl-F) and switch to the GREP tab.
  3. Set the Search pop-up menu to “Selection” (so only the selected text is modified).
  4. Copy this (including the initial colon) into the Find what field
    :|[-](?!(f|he|nd?|o|y|rom|or)?)
  5. Leave the Change what field blank, but click in the Change Format section and turn on the All Caps styling.
  6. Click Change All to make the change.

In Peter’s words:

The words to ignore are in the list separated by vertical bars, without their first letter: (f|he|nd?|o|y|rom|or) tells the GREP to skip of, and, in, on, to, from, and for (nd? matches an, and, in, on; the single letter o matches to). It may overgeneralise a bit in that ‘if’ and ‘she’ are kept in lower case, which might not be correct, but preventing that is complicated and makes the expression even more unreadable than it already is; and the errors it makes are so few that some manual editing doesn’t bother me. The GREP does two more things: it converts to upper case any word that follows a colon or a hyphen.

He then points out that you can add more words to the exclusion list by typing them — without their first letter, and separated by a vertical bar — in the list. For example, I noticed that “but” was being capitalized, so I added that by changing the grep expression to: :|[-](?!(f|he|nd?|o|y|rom|or|ut)?)

Perfect solution? Far from it. In my newer example, the words “gut” and “shut” won’t get capitalized. But I still think it’s better than Adobe’s built-in solution. Thank you, Peter!

Remember that you can save your Find/Change queries, so after you set this up once, click the Save button (it looks like a floppy disk icon… how quaint!) and give it a name.

Note that you can find more GREP solutions in the Search feature on this page (upper-right corner); we’re also developing a list of GREP solutions here.

Bookmark
Please login to bookmark Close

This article was last modified on December 18, 2021

Comments (34)

Leave a Reply

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

  1. Chris Voros-Haynes
    May 15, 2019

    Hi Jean

    If you only want to change the first letter of the first word of a paragraph then use the following:

    ^\<\w

    and apply a "CAPS" character Style

    ^ (Beginning of Paragraph)
    \< (Beginning of Word)
    \w (Any Word Character)

  2. December 27, 2018

    I do this using GREP in paragraph styles:
    First caps letter
    \<[\l\u]

    No caps letter
    (?i)the |or |by |of |on |at |with |in |and |see |de |to |'s|-\l+-|(?i)page
    (you can add or remove other conditions that won't be necessary to capitalise)

    1. Chris Haynes
      December 27, 2018

      Hi Ricardo

      \<\w(?=\w{3,}) CAPS

      This I what I use as it applies capitals to the first letter to a word that is 4 (1+3) characters in length or longer as (generally) the words you don't want to be capitalized are less than 4 characters in length … Of course, there are some exceptions which you can then do a local override for

      1. Jean-Lou Désiré
        May 15, 2019

        HI How can include the first letter of the first word. Thanks

  3. Andy McGinnis
    November 15, 2018

    Hi,

    Does anyone know how I can make this work for selected text in multiple table cells? When I run the query currently, the first letter of each word in each cell isn’t capitalized, but the rest of the words DO have their first letter capitalized (Hope that makes sense). Ideas?

    Thanks in advance!

    1. Chris Voros-Haynes
      November 16, 2018

      Hi check to see if you have any other grep or nested or character styles that might be overriding the first word … are you using my suggested grep style? … \<\w(?=\w{3,})

  4. Chris Haynes
    June 6, 2016

    GREP style : CAPS

    \<\w(?=\w{3,}\s)

    Change first letter of any word larger than 3 letters

    (It is not perfect)

    1. Chris Haynes
      June 6, 2016

      – EDIT you dont want the space at the end

      \<\w(?=\w{3,})

  5. ayman sayed
    May 26, 2015

    how can i convert al numbers
    before
    4846303
    393251561
    44010
    14560656
    12702185
    44763

    that what i need
    4,846,303
    393,251,561
    44,010
    14,560,656
    12,702,185
    44,763
    how can i do it please

    1. ayman sayed
      May 26, 2015

      Thanks :D:D:D:D

    2. May 26, 2015

      Not sure how your question is relevant to this article, but in any case, check out this free script: https://www.id-extras.com/script-to-format-long-numbers

  6. Chris
    January 6, 2015

    :\s\l|[-\s]\l(?!(f|he|nd?|o|y|rom|or)?\b)

    Hi Can someone please explain what this GREP code is actually doing?

  7. […] plug-in from InTools (does Change Case magic) > Change Case with GREP, InDesignSecrets post here and forum thread here > Using Configurator in InDesign to change case > Is it Upper Case or […]

  8. January 14, 2011

    Very nice. I just made this part of my SubHead Style Sheet.

    I just created a Character Style “All Caps”
    Clicked the “Basic Charcter Format” from the list and selected “All Caps” from the dropdown selection for Case:

    Then I edited my SubHead Style Sheet in the GREP Style section. Click New GREP Style, paste the command string from above :\s\l|[-\s]\l(?!(f|he|nd?|o|y|rom|or)?\b) and select “All Caps” for the Apply Style selection.

    Hope this proves helpful for other InDesigners.

    1. Rombout Versluijs
      December 30, 2016

      How can i also add 2 letter words? It doesnt get the words which have 2 letters

    2. Ann
      June 26, 2014

      Previous entry worked perfectly.

  9. October 29, 2010

    This looks great. I need to have a style sheet that forces the text into Title Case. How do I get the correct GREP command string to put into the paragarph style sheet?

  10. Jongware
    January 15, 2010

    Ken (better late than ever!),

    The GREP does two more things: it converts to upper case any word that follows a colon or a hyphen.
    The colon stuff is in the first half, before the very first pipe character.

    Jenn, that GREP should be

    ^[^:]+:

    I can go into great detail on this GREP expression when asked … ;-)

    However, there are more than a few problems. You can apply “[None]”, either with search & replace, or using a nested grep style. But: applying the None char style doesn’t do anything. It removes present character styles, but the original formatting is preserved.
    You can create a new character style in which you set every possible attribute to Normal (not underlined, normal case, no superscript, etc. for everything). That does not work in a GREP style for manually applied formatting, you need a search-and-replace for that.

  11. jenn stockwell
    January 15, 2010

    Hi David,

    I realize this is slightly off topic, but I am trying to do what seems like a relatively simple find/change using GREP and can’t quite get it to work.

    I need to search for everything up to and including a colon at the beginning of a paragraph and set the character style sheet to ‘none.’

    I can go into detail if you need, but it’s sort of complicated, the reasoning behind it…

    Thanks for any help!!

  12. Ken Darby
    February 26, 2009

    At the risk of sounding like a GREP newbie, which I am,
    what purpose does the initial colon serve in this expression? I can neither find it on Mike Witherell’s cheat sheet nor at http://www.regular-expressions.info.

    Snip
    —–
    Copy this (including the initial colon) into the Find what field
    :sl|[-s]l(?!(f|he|nd?|o|y|rom|or)?b)

  13. Eugene Tyson
    September 25, 2007

    Yeh I know, I did really well up to the last sentence.

  14. Peter Kahrel
    September 25, 2007

    >who wants one to do things in InDesign anyway?

    Nice Freudian slip :)

    Thanks for the nice words. You’re right: it shouldn’t be so difficult to do something with an editable list, similar to Autocorrect. Let’s hope it’ll make it in the next version. There have been many requests for it.

    Peter

  15. Eugene Tyson
    September 25, 2007

    Edit to last line: Which is great, because who wants one to do things one way in InDesign anyway?

  16. Eugene Tyson
    September 25, 2007

    Hi Peter, my intention was not to divert attention from the GREP solution. I didn’t mention that I like the GREP solution and I think it’s great. You could use this solution for a lot of things. Like if you wanted certain words to be a cap first letter perhaps in the sentence. So you could search multiple words or variants of these words to make UpperCase and so on.

    I still for the life of me can’t figure out after 3 versions of CS that there is no option in the Paragraph or Character styles to have Title Case and so on, or have an editable table or something that can adjusted accordingly for Title Cases, leaving out conjunctions or in as needed. It’s just something that has annoyed me, and I read somewhere that Adobe had corrected this in CS3 but the feature just wasn’t there.

    Nor was it included in the few free GREPs that were included by default.

    I just don’t want you think that I haven’t taken note of this code and saved it in my GREPs for future use or reference, because I have.

    I only thought to mention the script because I feel I’m not alone in not having Smart Title Cases. Now am I not only not alone but I’ve also got 2 ways of achieving the same thing. Which is great, because who wants one to do things in InDesign anyway?

  17. Peter Kahrel
    September 25, 2007

    A script is obviously more versatile and powerful for things like title case. The point of this example was to show that you can get very far with GREP expressions.

    Peter

  18. September 24, 2007

    One piece of advice I would give people using that script is: if you use and external text file to hold the words, change the internal array definition to say that’s what you’re doing so you don’t waste time editing the array inside the script only for it to be ignored because of the text file you forgot about.

    Does it sound as though I’m speaking from experience?

    Dave

  19. September 24, 2007

    Thanks, Bob, and thanks very much, Dave! Yes, I should have remembered that script. It’s very good, and much easier than the GREP solution. (Though the GREP is more fun, as it makes your eyes boggle when you look at it.)

  20. September 24, 2007

    It is indeed Dave’s script. It can be downloaded from here:

    https://jsid.blogspot.com/2006/06/smart-title-case-revisited.html

  21. Eugene
    September 24, 2007

    I got a script from someone, perhaps Mr. Dave Saunders, called, Smart Title Cases, I’ve been using it for a while now, I can’t find and replace with it or set it as part of the Style, but I can use a shortcut for it. Still better than selecting individual words and etc.

  22. September 24, 2007

    I totally agree with both points, Sandee! Adobe? You listenin’?

  23. September 24, 2007

    But the true moral of the story is that we need two improvements to the Change Case command.

    #1: A list of exclusions for the Title Case command as well as a list of exclusions for the Make Lowercase command.

    #2: A way to apply the command as part of a Find/Change routine.

  24. Eugene
    September 24, 2007

    Often when I’m running my GREPs I want certain things to remain untouched, like the body text or a the second and third level headings. So I only run the search on that particular Paragraph Style, rather than selecting the text manually.

  25. September 24, 2007

    Hey, it’s Monday morning; I can’t be expected to write entirely coherently! ;)

    I’ve gone ahead and changed the step-by-step above to answer the questions: Yes, use this instead of Title Case; and Yes, you should select the text you want to change first.

  26. September 24, 2007

    I love this, but I’m a little unclear on a couple things.

    – Is it a replacement for the Change Case > Title Case command? Or are you supposed to run it on titles you’ve already changed, to uncapitalize the listed words.

    – I assume you’re supposed to select the text first and make sure the Find/Change is run on the Selection, yes? Or is it smart enough to recognize which bits of a story are titles and which are not. I’d be really surprised if it could do that … heh … but you/Peter didn’t mention setting the scope of the F/C so I feel compelled to ask.