Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

General Discussions has some can't miss conversations going on right now! From conversations about automation to sharing your favorite Alteryx memes, there's something for everyone. Make it part of your community routine!

SOLVED

Regex extracting after last underscore

vineetamishra
5 - Atom

I need help with extracting value after last underscore from below string example. 

 

Example string is       AB_1234567_awesome-weather_think_so_whatever_9876543 

Expected Solution is  9876543

Appreciate your time & help.

PhilipMannering
14 - Magnetar
14 - Magnetar

You want to set the Regex tool to parse and use the pattern,

.*_(\d+)

Hope this helps,

Philip 

PhilipMannering
14 - Magnetar
14 - Magnetar

If it's not digits at the end then you can just use,

 

.*_(.*)

 

Or if it is definitely just digits, you could also use,

(\d+)$

 

vineetamishra
5 - Atom

This works! thank you so much Philip.

PhilipMannering
14 - Magnetar
14 - Magnetar

Some non-regex methods for you,

 

If you're feeling brave,

reversestring(getword(replace(ReverseString([Field1]), '_', ' '), 0))

 

If you're feeling clever,

FileGetFileName(replace([Field1], '_', '/'))

 

MarqueeCrew
19 - Altair
19 - Altair

@vineetamishra,

 

As "solved" by @PhilipMannering you are using a regular expression (a hammer) where a string function is called for.

 

Right([Example String],Findstring(ReverseString([Example String]),"_"))

 

The RegEx is roughly 2x as expensive as this combination of string functions is.  The reverse string function combined with the find string function determines the LENGTH required of the right function.

 

Both solutions work. 

 

Cheers,

 

Mark 

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
MarqueeCrew
19 - Altair
19 - Altair

@PhilipMannering ,

 

I'm glad to see that you posted an alternative to the RegEx expression.  I'm happier to see a different string function than the one that I posted.  For bonus happiness, I'm glad to see that my expression is still the fastest.

 

I think that getword() is an expensive function.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
PhilipMannering
14 - Magnetar
14 - Magnetar

@MarqueeCrew 

 

Good to know! Can you attach your (or a) workflow for comparing the speed of each method? I'd quite like to know how I can assess which methods are the best quickest.

 

P

MarqueeCrew
19 - Altair
19 - Altair

@PhilipMannering ,

 

 I'm not in front of my computer now but.....

 

text input - generate rows (1,000,000)

 

 cache the generate rows

 

 connect this to a formula tool and place that tool into container 1. 

repeat for formula/ container 2. 

turn on workflow configuration runtime option for performance monitoring. 

for each formula (other container disabled) run 3 times. 

take the middle timings from the results messages. 

 

Example:

 

1000 ms vs 2000 ms

1.9 seconds vs 2.9 seconds

 

 I'll create a YouTube video tomorrow morning. 

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
MarqueeCrew
19 - Altair
19 - Altair

P.S.  I've created a new post documenting the performance profiling technique that I used.

 

MarqueeCReW-Quick-Lesson-Performance-Profiling 

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Labels