Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Question about using regex with if functions

wht822
7 - Meteor

I couldn't find the answer to this question anywhere else on this forum, so I apologize if this has been asked before.

 

I'm trying to enter a regex function into an if field so I can identify certain data sets. In this case, I'm trying to apply an if function to records that contain a date in "mm/dd/yyyy" format at the beginning of the record and end with either a percentage sign (%) or a decimal followed by two numbers.

 

An example of a record might look something like this: "03/23/20 12.000 210.6380 2,527.65 379.9100 4,558.92 2,031.27 7.68 0.16%"

 

Or this: "03/23/20 14.000 306.0690 4,284.97 435.3100 6,094.34 1,809.37"

 

If a record contains something within either format listed above, then I want a new field to display "Format 3."

 

I'd really appreciate if someone could help point me in the right direction. Thanks!

2 REPLIES 2
Qiu
21 - Polaris
21 - Polaris

@wht822 

Something like this?

Appreciate if you would mark it as acceptable if you think it works for you.

1029-wht822.PNG

vizAlter
12 - Quasar

Hi @wht822 — Try this solution:

 

REGEX_Replace([Field1], "^(\d{2}/\d{2}/\d{2}\s.*)(?=\.\d{2}%|\.\d{2})", "")

then

  IF   REGEX_Match([Result], "^\.\d{2}\%$")  OR  REGEX_Match([Result], "^\.\d{2}$") THEN 
    "Format 3." 
  ELSE 
    Null() 
  ENDIF

vizAlter_0-1603942116004.png

 

Labels
Top Solution Authors