FORUMS: list search recent posts

Expression that Capitalizes first letter of each word

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Expression that Capitalizes first letter of each word
on Jun 7, 2017 at 8:23:30 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.


Return to posts index

Dan Ebberts
Re: Expression that Capitalizes first letter of each word
on Jun 7, 2017 at 9:50:38 am

Try this for source text:


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



Dan



Return to posts index

Scott McGee
Re: Expression that Capitalizes first letter of each word
on Jun 7, 2017 at 4:49:13 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.


Return to posts index


Dan Ebberts
Re: Expression that Capitalizes first letter of each word
on Jun 7, 2017 at 5:56:41 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



Return to posts index

Scott McGee
Re: Expression that Capitalizes first letter of each word
on Jun 7, 2017 at 6:34:06 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.


Return to posts index

Ngoc Mai Sixomphon
Re: Expression that Capitalizes first letter of each word
on Jun 8, 2017 at 9:10:41 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.


Return to posts index


Dan Ebberts
Re: Expression that Capitalizes first letter of each word
on Jun 8, 2017 at 4:24:08 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



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]