Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Don't forget to submit your entry for the Excellence Awards by October 30! | Need more information about the program? Check out the blog here
SOLVED

Regex help!

Highlighted
9 - Comet

Trying to replace the last part of this string after the comma(XYZZA) only in cases where it doesnt end with '_General'

 

FY18,Other Customer,XYZZA

FY18,Other Customer,ABC_General

 

Current regex is below but it doesnt work as it looks for any of the letters in general, not the entire word.

,([^(_General)]+)$

 

Just cant seem to figure out how to use [^] condition for an entire word.

Thanks!

Highlighted
Alteryx Certified Partner

Hi @brindhan 

 

Solution is attached. 

 

Snag_816d7596.png

 

 

By first using a REGEX_MATCH formula, we can determine whether the string ends with '_General' and take steps from there. As per the logic, if the string ends in 'General' then we will keep as is. Otherwise, remove the last part of the string after the comma. The below formula will get this done:

if regex_match([Field1], '^.*_General$') then [Field1]
else regex_replace([Field1], '(.*,).*', '$1')
endif

 

Hope this helps!

Highlighted
9 - Comet

This is awesome, thanks @lmorrell !

Labels