In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

RegEx help

cstafford
8 - Asteroid

Looking for some help with RegEx as I do not use this very often. I could use the Parse tool but hoping to learn a bit more about RegEx. I am looking to take a string that has underscores and also varies in length. I am looking to exclude the far right of the string for each entry to include the last underscore. Any help appreciated.

 

Examples

123_12345_12345678910

12345_123456_12345678910

12_123456789_12345678910

 

Result

123_12345

12345_123456

12_123456789

7 REPLIES 7
alexnajm
19 - Altair
19 - Altair

Try (.+)_.+

 

This is saying, with the parentheses, to give you one or more characters before the last underscore, and ignore the underscore and anything afterwards. 

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Hi @cstafford ,

 

Here is a sample formula to output your expected result. I hope this helps.

 

Formula

Result = REGEX_Replace([Examples], "(.+_.+)_.*", "$1")

 

Output

ExamplesResult
123_12345_12345678910123_12345
12345_123456_1234567891012345_123456
12_123456789_1234567891012_123456789
jdminton
13 - Pulsar

@cstafford  (.+)([_]) will work in the RegEx tool with parse method. I couldn't determine based on your request if you wanted the last underscore or not, so I included it in the second output field instead ;)

 

@alexnajm I couldn't get your expression to work with the sample data.

alexnajm
19 - Altair
19 - Altair

It works for me @jdminton! I put the parentheses around the second part to check 

IMG_3769.jpeg

flying008
15 - Aurora

Hi, @cstafford 

 

1- RegEx Function:

 

 

REGEX_Replace([Txt], '_\d+$', '')

 

 

录制_2023_07_04_09_13_49_135.gif

 

jdminton
13 - Pulsar

@alexnajm That's funny. It works today. I'm not sure why it's different. It's literally the exact same expression!

cstafford
8 - Asteroid

Thanks for all the help here, greatly appreciated.

Labels
Top Solution Authors