In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Regex , If String occurs once then Trim all punctuation, If Twice, use AND

wonka1234
10 - Fireball

Hi,

 

I am trying to use regex to solve this issue, can this be done? Left is my input, right is expected output.

, , , Met Current ValidationMet Current Validation
, Met Action Plan Validation, , Met Action Plan Validation
Met Action Plan, , Met Current Resolution, Met Action Plan AND  Met Current Resolution
Met Action Plan, , Met Current Resolution, Met DateMet Action Plan AND Met Current Resolution AND Met Date
4 REPLIES 4
apathetichell
20 - Arcturus

I got lazy here and used three formula tools - blah. someone else could have done this with one.

 

formula 1:

output

Regex_replace([input],"^\U{1,}","")

 

formula 2:

output

Regex_replace([output],"\U{1,}$","")

 

formula 3:

regex_replace([output],"\U{2,3}"," AND ")

 

Prometheus
12 - Quasar

@wonka1234 You could do it with three expressions in one Formula tool. In my workflow, I called the field "Text." The first expression would be to find where a comma is followed by a space and replace it with two spaces: REGEX_Replace([Text], '(,\s)+', ' ')

 

The values that end up with leading and/or trailing spaces can be cleaned up using the Trim function:TRIM([Text])

 

After that, you'll have to find the double space between values and replace it with " AND ": Replace([Text], ' ', ' AND ')

Replace Commas.PNG

flying008
15 - Aurora

Hi, @wonka1234 

 

FYI.

Spoiler
Replace(Trim(REGEX_Replace([Txt], '(,\s?)+', '|'),'|'), '|', ' AND ')

录制_2023_11_07_09_06_45_870.gif

 

caltang
17 - Castor
17 - Castor

Like so?

 

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Labels
Top Solution Authors