Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Get the Position of the Last Instance of a String Within a String

RonGatmaitan
8 - Asteroid

Hello,

 

Please help me find the last instance of a string within a string.

 

For Example, I want to find ABC in this string.

 

123ABC456ABC789ABC

 

It should return 16, because it's the last instance of ABC.

 

Thank you.

8 REPLIES 8
caltang
17 - Castor
17 - Castor

Like so?

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
caltang
17 - Castor
17 - Castor

In case anyone wants the expression only...

LENGTH([Field1]) - (FINDSTRING(REVERSESTRING([Field1]), REVERSESTRING("ABC")) + 2)

 

Referenced solution courtesy of @MarqueeCrew : https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/Last-instance-of-a-character/t... 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
flying008
15 - Aurora

Hi, @RonGatmaitan 

 

1- If your "ABC" is manual input, then use the formula:

 

 

Length(REGEX_Replace([Txt], '^(.*?)ABC[^A-Z]*?$', '$1')) + 1

 

 

2- If input from filed, then 

 

 

Length(REGEX_Replace([Txt], '^(.*?)' + [FindStr] + '[^A-Z]*?$', '$1')) + 1

 

 

gawa
16 - Nebula
16 - Nebula

hi @RonGatmaitan 

 

You can use ReverseString function of Formula tool. Please find the attached workflow.

*Alteryx normally counts string position from 0 index basis, but it seems you start count from 1, my WF is made so.

image.png

caltang
17 - Castor
17 - Castor

@RonGatmaitan as you can see, many ways to do it. Excellent solutions by @flying008 and @gawa !

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
RonGatmaitan
8 - Asteroid

Thanks for the replies, @caltang, @gawa and @flying008! Will try these out!

caltang
17 - Castor
17 - Castor

If it helps, you can mark @gawa @flying008 and my solution as accepted solutions to close the thread! Thanks @RonGatmaitan !

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
RonGatmaitan
8 - Asteroid

Done, @caltang! Thanks to all 3 of you!

Labels
Top Solution Authors