Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Community is experiencing an influx of spam. As we work toward a solution, please use the 'Notify Moderator' option on the ellipsis menu to flag inappropriate posts.

Alteryx Designer Desktop Discussions

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

Trim muliple parts of a string

Jmills040
6 - Meteoroid

I have a field populated with strings with this name - file_hr_all_organization_units_f_20170505_020058203 - how do I remove the 'file_' portion and '_20170505' portion from the string, but keep the rest in one formula?

2 REPLIES 2
NicoleJohnson
ACE Emeritus
ACE Emeritus

Try copying/using this expression with Replace output method in the RegEx tool (splits your string into 4 marked groups and then returns just the 2nd & 4th groups):

 

(.*)(hr_all_organization_units_f)(_\d{8})(.*)

 

Or... you can use the RegExReplace formula in the Formula tool (same result as above, just does it with a formula instead of the RegEx tool):

 

REGEX_Replace([Field1], "(.*)(hr_all_organization_units_f)(_\d{8})(.*)","$2$4")

 

Does that work? :)

 

NJ

DanS
9 - Comet

Hey Jmills040, 

 

I attached a quick example of using Regex and Trim to do this that seems to get your desired result. 

 

Matching up to and including the first "_" from the beginning of the string and the end of the string.

I had some trouble with the regex expression for removing the last underscore. So I used the trim tool to take off the last one.

 

Thanks!

Dan 

Labels