Alteryx Designer Desktop Discussions

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

Help with RegEx replace syntax

jannis005
7 - Meteor

Hi -

 

I have a string data field with trailing shareclass identifiers that I want to remove.

 

Example: ABC Fund CL A, where "CL A" is the text I am trying to remove.

 

I am trying to create a simple RegEx replace tool that finds that "CL" and replaces "CL" and anything that follows with nothing, but was struggling with the syntax to accomplish this. Can anyone help?

 

Thanks in advance.

4 REPLIES 4
LordNeilLord
15 - Aurora

Hey @jannis005

 

Something like this should do the trick:

 

Regex_Replace([Field1],"(.*)(CL.*)","$1")

jdunkerley79
ACE Emeritus
ACE Emeritus
Regex_Replace([Field1],"CL .*?$","")

Should work as well

 

It will match the last 'CL ' in a string and then replace it and anything else with "".

 

MarqueeCrew
20 - Arcturus
20 - Arcturus

@jannis005,

 

Far be it from me to try to interfere with @jdunkerley79 's quest for solution glory.  If you have a fund name like this:  

 

Clough Funds Trust: Clough Global Long/Short Fund; Class I Shares

 

His expression is going to miss out on the desired results.  I wrote the following expression:

 

REGEX_Replace([Fund], "(.*)\WCL.*", '$1')

It returns:

 

Clough Funds Trust: Clough Global Long/Short Fund;

 

You can modify the expression to remove the semi-colon if it is really present or trimright(fund,";") will work easily enough.

 

Cheers,

 

Mark

 

P.S. It is perfectly acceptable to mark multiple solutions on your post.  I'm just giving James a run for his money.

Alteryx ACE & Top Community Contributor

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

Thanks for the help everyone!

Labels