From: "Lloyd Alvarez" Received: from c147c-aesc.jetrails.io ([69.27.38.85] verified) by media-motion.tv (CommuniGate Pro SMTP 6.1.0) with ESMTPS id 7440402 for AE-List@media-motion.tv; Wed, 25 Sep 2019 18:07:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aescripts.com; s=default; h=Content-Type:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ESBOuKmo2v1LICz1xtGw9wW1XS0YWzuv5v46/tIUY9E=; b=WGae33tBP3nkJM9zTztKm+cqM MW0xons0P6vhzUVPzgXVacSz74pR5ZnFpJ6NYmqOJnin7ELdkGOHx5Hn7H2061/A2ImyVj8394Tub uDAzYKlR9fmY7jqpjCSL2F+Hnl6KBSopiHpInQWFYErMWanxRVXub1TaGBovdHCLdGMpDXL99lDT3 jikfdA+l+2lncT9018YVLqXjWMKpJre3+6RW3DQuHAZJD3p4BiBFKWZ5ZsySVgJWU4lcsKomiQrmV yUDZkqpaP/3SQYmpQsV3sw+0DaNb6IZXl5RMgb9iyyDhlUHexUsXSLO0wSVbuZzRIYGpDMjHxw/8t YX4jfuJ3g==; Received: from mail-ua1-f51.google.com ([209.85.222.51]:45433) by c147c-aesc.jetrails.io with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iD9rt-0001xb-PT for AE-List@media-motion.tv; Wed, 25 Sep 2019 16:10:17 +0000 Received: by mail-ua1-f51.google.com with SMTP id j5so11351uak.12 for ; Wed, 25 Sep 2019 09:10:17 -0700 (PDT) X-Gm-Message-State: APjAAAXaTKkg28AOrp88hZeBKqy8Nygp1lK3BG52ZK+jy59gMbyWtyZ7 Kp+l6vScUenEPRBzqtT+NLOJImJ8A/MPGR2I2yk= X-Google-Smtp-Source: APXvYqxwbKOgW1eBzTcz4VyYE6tGhJArwzQ9j+lt1cTZmw3nVzyjufmnTrXuPdyugBxehk3inrPN4h5tdIUrg0r856o= X-Received: by 2002:ab0:7c4:: with SMTP id d4mr5413168uaf.116.1569427817296; Wed, 25 Sep 2019 09:10:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 25 Sep 2019 12:09:41 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [AE] Regex help on expression To: After Effects Mail List Content-Type: multipart/alternative; boundary="0000000000008cfba5059362e3ad" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - c147c-aesc.jetrails.io X-AntiAbuse: Original Domain - media-motion.tv X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - aescripts.com X-Get-Message-Sender-Via: c147c-aesc.jetrails.io: authenticated_id: smtp@aescripts.com X-Authenticated-Sender: c147c-aesc.jetrails.io: smtp@aescripts.com X-Source: X-Source-Args: X-Source-Dir: --0000000000008cfba5059362e3ad Content-Type: text/plain; charset="UTF-8" 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 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 > 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 >> 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 >>> 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 >>>> wrote: >>>> >>>>> Try this: >>>>> >>>>> *text.sourceText.match(/*[0-9]+(ST|ND|RD|TH)*/g);* >>>>> -- >>>>> Cheers, Lloyd >>>>> >>>> --0000000000008cfba5059362e3ad Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
btw, forgot that match also returns an index but only when= you are not using the "g" global flag. with exec you can loop th= rough it to find the index of all the occurrences. so this would also work = if you dont use "g":

var= match =3D text.sourceText.match(/[0-9]+(ST|ND|RD|TH)/);
if (match=C2=A0!=3Dnull){
=C2=A0 =C2=A0 match.index += =C2=A0match[0].length;
<= b>}
<= b>
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

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

var match =3D (/[0-9]+(ST|ND|RD|TH)/g).e= xec(text.sourceText);
if (= match=C2=A0!=3Dnull){
=C2=A0 = =C2=A0 match.index +=C2=A0match[0].length;
}


Cheers,
Lloyd

<= /div>
O= n Wed, Sep 25, 2019 at 11:32 AM Byron Nash <AE-List@media-motion.tv> wrote:
=
Th= anks. I see what=C2=A0you mean about arrays. Most of my inputs will only re= turn one result. I was hoping to get an index to find where the string star= ts so I can subdivide the original string. The regex that you wrote is retu= rning a -1 index no matter what it is fed. In my other tests with my origin= al regex, I was getting an index. Both are using match so I'm not sure = why it's doing that.=C2=A0

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

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

var theTextArray =3D=C2=A0text.sourceText.match(/[0-9]+(ST|ND|RD|T= H)/g);
var theText = =3D (theTextArray !=3D null && theTextArray.length >=3D2) ?=C2= =A0theTextArray[1] : "";
theText;

=
Cheers,
Lloyd
=
aescripts + aeplugins


On Wed, Sep 25, 2= 019 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 jus= t 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 Alva= rez <AE-Lis= t@media-motion.tv> wrote:
Try this:

text.sourceText= .match(/[0-9]+(ST|ND|RD|TH)/g);<= /font>
--
Cheers, Lloyd
--0000000000008cfba5059362e3ad--