Alteryx Designer Desktop Discussions

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

Regex help!

brindhan
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!

2 REPLIES 2
lmorrell
11 - Bolide

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!

brindhan
9 - Comet

This is awesome, thanks @lmorrell !

Labels