Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression that Capitalizes first letter of each word

  • Expression that Capitalizes first letter of each word

    Posted by Scott Mcgee on June 7, 2017 at 8:23 am

    Hey Guys,

    Hopefully something quick and simple.

    I need an expression that will capitalize the first letter of each word. Just incase someone hits the CAPS lock, I need to incorporate both toUpperCase and toLowerCase functions.

    I’ve been staring at my screen for a good hour and I feel it should be obvious and can’t find anything online to answer.

    Dan Ebberts replied 9 years ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    June 7, 2017 at 9:50 am

    Try this for source text:


    r = /(\b[a-z](?!\s))/g;
    txt = value.toLowerCase();
    txt.replace(r, function(x){return x.toUpperCase();});

    Dan

  • Scott Mcgee

    June 7, 2017 at 4:49 pm

    Genius Dan,

    Just because this is the first time, yourself or anyone have given me an expression that I couldn’t work out myself when reading it.

    Could you break this down please. As I haven’t the foggiest what any of the line 1 means passed r =. line 2 I get the gist and line 3 is a bit of a mystery aswell passed txt.replace.

  • Dan Ebberts

    June 7, 2017 at 5:56 pm

    The first line defines a regular expression (regexp). These have their own compact and cryptic syntax for pattern matching. The JavaScript string.replace() will accept a regexp as the first parameter (the what-to-replace part). This particular regexp matches the first character of each word. For the second replace() parameter, I’m using a function to convert all the matching characters (produced by the regexp) to upper case.

    Hope that helps. Just Google regular expression if you really want to dig into it. Very powerful, but there’s a learning curve.

    Dan

  • Scott Mcgee

    June 7, 2017 at 6:34 pm

    I just about understand.

    when i googled and read the first line on the first page I opened

    A regular expression, regex or regexp[1] (sometimes called a rational expression)[2][3] is, in theoretical computer science and formal language theory,

    First thing I thought…I hate my life right now.

    But watched 1 youtube video, it seems straight forward.

    Thank you for explaining.

  • Ngoc Mai sixomphon

    June 8, 2017 at 9:10 am

    Hi Dan!
    It’s my very first Post and i even made an account in Creative Cow because I really need to know this!

    So, I need to work out a Typo Template for a client. And just as Scott, I need the fist letter of a word to be capatilized.
    Because my client doesn’t really know how to use AE, I have conntected the Text layer to an empty comp by using this expression on the text source: comp(“Adventure_Drama ◊ Adventure ◊ Time”).name.split(” ◊ “)[1]. In the end, the client only needs to type the text on the empty comp instead of going in the comp and messing with the text layer. The Problem ist that each first letter is 160 px big and all other (lowercase) letters are 110 px big. When using this expression, it automatically sets up all my letters to 160 px and capatilized them.
    And when using your given expression, it won’t work. Not even if i blend my expression out.
    What did I miss ?

    Sincerely,
    Nocki

    \”Mai\” belongs to my first name. Not last name. But CreativeCow won\’t accept it.

  • Dan Ebberts

    June 8, 2017 at 4:24 pm

    So your text layer has a different font size defined for the first character, is that correct? Whenever you apply an expression to the source text, as it sounds that you have discovered, all characters get the formatting of the first character. I would suggest converting the text into two layers and using sourceRectAtTime() to find the appropriate edge of the first character to re-position the second text layer.

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy