Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
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.

9 REPLIES 9
PhilipMannering
16 - Nebula
16 - Nebula

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

.*_(\d+)

Hope this helps,

Philip 

PhilipMannering
16 - Nebula
16 - Nebula

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
16 - Nebula
16 - Nebula

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
20 - Arcturus
20 - Arcturus

@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 restart. Order shall return.
Please Subscribe to my youTube channel.
MarqueeCrew
20 - Arcturus
20 - Arcturus

@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 restart. Order shall return.
Please Subscribe to my youTube channel.
PhilipMannering
16 - Nebula
16 - Nebula

@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
20 - Arcturus
20 - Arcturus

@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 restart. Order shall return.
Please Subscribe to my youTube channel.
MarqueeCrew
20 - Arcturus
20 - Arcturus

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 restart. Order shall return.
Please Subscribe to my youTube channel.
Labels