Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Regex to subset a string between " - "

rev
7 - Meteor

So, I have the following data in a single column:

10-Junior-32

101-Senior-23

102-Senior Pres-34

01-Senior Pres XYZ-30

 

and this is the desired output:

Junior

Senior

Senior Pres

Senior Pres XYZ

 

I am trying to subset the string between the "-".

Since neither the position is set or the number of characters to take out.

I can only think of regex which could subset the string between "-" and put it into a new column. That is the desired output.

 

Any thoughts or suggestions would be highly appreciated. Thanks!!!

4 REPLIES 4
JohnJPS
15 - Aurora

Hi @rev,

I believe this should work: a formula tool creating your new column using the expression...

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

... where [f1] is your original field.

 

The same concept can be achieved with the RegEx tool.

 - John

 

MarqueeCrew
20 - Arcturus
20 - Arcturus
I agree with John. If the matching data is always numeric that you are discarding, you could change this to:

\d+-(.*)-\d+

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
rev
7 - Meteor

Thanks John for your solution! I plugged it in and it worked.

Have a great day!

rev
7 - Meteor

Thanks @MarqueeCrew for your input. There might be cases where there's more than just digits on either side of the "-" delimiter. Thanks!

Labels