Alteryx Designer Desktop Discussions

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

Trim anything left after the latest dash character

adombayeva
7 - Meteor

Hello,

Could you please advise how to trim anything left after the latest dash " - " . There are several " - " in the string, so I am focused only whatever comes after the latest " - ". It will great if you could also explain the expression. 

 

Text:

2019 KWK Competitive scoping - Grand *Total - 09 Tut A'more

 

The desired output: 09 Tut A'more

 

Thanks

3 REPLIES 3
danilang
19 - Altair
19 - Altair

Hi @adombayeva 

 

You can use the following

 

REGEX_Replace([Field1], ".*-(.*)", "$1")

 

.*- This matches any characters up to and including a dash.  Because Regex is greedy by default, any hyphens that appear before the last one are caught by the ".*", so the expression matches everything up to the last hyphen

(.*) The ".*" will match any number of characters.  Since it's surrounded by brackets, its seen as a capturing group.  Any characters that match this pattern are captured and can be used later.  Since this is the first group you use "$1" to refer to it.  This is used in the replace clause to replace the entire contents of Field1 with the characters that follow the last hyphen

 

Dan

 

adombayeva
7 - Meteor

Hi @danilang,

 

Thank you very much for support! The expression helped me to solve the issue and your explanation became an invaluable knowledge for me to practice further! 

 

Cheers 🙂

 

Anthony_A2
5 - Atom

Hi @danilang

 

How would you reverse this if you wanted to trim everything after the last hyphen?

 

I have an instance where I have a column of identifiers with variable amount of hyphens in each record. I always want to grab everything before the last hyphen. 

 

Thanks!

Labels