Mailing List AE-List@media-motion.tv — Message #65620
From: Lloyd Alvarez <AE-List@media-motion.tv>
Subject: Re: [AE] Regex help on expression
Date: Wed, 25 Sep 2019 12:09:41 -0400
To: After Effects Mail List <AE-List@media-motion.tv>
btw, forgot that match also returns an index but only when you are not using the "g" global flag. with exec you can loop through it to find the index of all the occurrences. so this would also work if you dont use "g":

var match = text.sourceText.match(/[0-9]+(ST|ND|RD|TH)/);
if (match !=null){
    match.index + match[0].length;
}

Cheers,
Lloyd


On Wed, Sep 25, 2019 at 12:03 PM Lloyd Alvarez <AE-List@media-motion.tv> wrote:

> I was hoping to get an index to find where the string starts so I can subdivide the original string

Why do 2 steps when the regex should be able to match anything you need,  but if you need the index then use exec instead of match:

var match = (/[0-9]+(ST|ND|RD|TH)/g).exec(text.sourceText);
if (match !=null){
    match.index + match[0].length;
}


Cheers,
Lloyd


On Wed, Sep 25, 2019 at 11:32 AM Byron Nash <AE-List@media-motion.tv> wrote:
Thanks. I see what you mean about arrays. Most of my inputs will only return one result. I was hoping to get an index to find where the string starts so I can subdivide the original string. The regex that you wrote is returning a -1 index no matter what it is fed. In my other tests with my original regex, I was getting an index. Both are using match so I'm not sure why it's doing that. 

On Wed, Sep 25, 2019 at 11:10 AM Lloyd Alvarez <AE-List@media-motion.tv> wrote:
Hey Byron

The regex I gave you returns an array with the second item in the array being the string, so first check to make sure the return is not null and then grab the second item:

var theTextArray = text.sourceText.match(/[0-9]+(ST|ND|RD|TH)/g);
var theText = (theTextArray != null && theTextArray.length >=2) ? theTextArray[1] : "";
theText;

Cheers,
Lloyd
aescripts + aeplugins


On Wed, Sep 25, 2019 at 8:20 AM Byron Nash <AE-List@media-motion.tv> wrote:
Thanks Lloyd, that does return the string plus the digits. Do I not need the lookbehind to just return the string? I tried adding the lookbehind back in but it doesn't work.

Nathan, I didn't run across that site but I will check it out, thanks!

On Tue, Sep 24, 2019 at 7:07 PM Lloyd Alvarez <AE-List@media-motion.tv> wrote:
Try this:

text.sourceText.match(/[0-9]+(ST|ND|RD|TH)/g);
--
Cheers, Lloyd
 
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to ListMaster