Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Conditional parsing regex (depending on value)

fomenter
8 - Asteroid

I have two coloumns one is for zip code which I'm using a regex (^([A-Za-z]{2})(\d{9}|\d{5})$) for, and the second one is country codes. I only would like to apply my regex where country code is "US".

 

Can i do it with the formula function, if not how?

 

I appreciate for your help

3 REPLIES 3
michael_treadwell
ACE Emeritus
ACE Emeritus

You should be able to use REGEX_Match() inside an IF ELSE statement:

 

IF [country] == 'US' THEN REGEX_Match([code], 'insert regex here') ELSE 0 ENDIF

I've attached a (simple) example

fomenter
8 - Asteroid

Thanks, can I use parse instead of match?

michael_treadwell
ACE Emeritus
ACE Emeritus

Realizing that you asked specifically to do this with the formula tool, I will first say that I think using a filter tool to grab all records where country == 'US', then using the regex tool to parse the codes, then using a union tool to recombine the records would be the easiest method.

 

That being said, with the formula tool specifically, I would suggest using REGEX_Replace() with the code I posted above with replace = '' to remove the part of the string that you do not want.

 

I could be misunderstanding your problem, though.

Labels
Top Solution Authors