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

Using REGEXReplace in a IF statement. Getting malformed statement.

Aviator0807
8 - Asteroid

So I want to replace an extra 0 that appears right after the "Z" I originally used the Regex tool and it worked except there are other serials that follow the same format that do not need to be replaced only those that start with 702Z0. So that brought me to the formula tool, below is the expression I am trying to use but is telling me it is malformed.

 

IF (StartsWith([Car Serial Number], "702Z0") AND Length([Car Serial Number]) == 7) THEN REGEX_Replace([Car Serial Number], "(\d+\w)\d(\d+)", "$1$2") ENDIF

 

So I know the first part (before THEN) works because I was originally using a regular replace and it worked but it was also replacing the 0 before Z (702Z)and at the end of the whole serial which I do not want it to do. It was only after I added the REGEX replace that things went south.  Any ideas what I am doing wrong or maybe another way to accomplish the same? 

 

Thank You

 

3 REPLIES 3
apathetichell
19 - Altair

before we get into your regex- you need an else clause. like else [car serial number]... if you are still having some problems - post some data.

Aviator0807
8 - Asteroid

Brainfart, I forgot the ELSE . Thank you !

apathetichell
19 - Altair

We've all been there!

Labels