Alteryx Designer Desktop Discussions

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

Regex(?) formula to remove values matching the ones stored in other field

kwieto
8 - Asteroid

Check two field, each containing multiple values, separated by "|" sign, against each other and list differences for each field.

So basically if field 1 has values like ABC|DEF|GHI and Field 2 has DEF|JKL I want to have two outputs:
For Field 1 - ABC|GHI (values which are not available in Field 2)
For Field 2 - JKL (value not available in Field 1)

 

I know that I can split both fields into rows, then use join to match same values and have differences listed in L and R output, but just for the sake of playing I am trying to do the same thing via formula. 
I created one which is basically Regex_Replace([Field 1], [Field 2], "") which, since the "|" sign stands for OR in RegEx, basically works. - in the above case it will translate to Regex_Replace("ABC|DEF|GHI", "DEF|JKL", "") and return ABC||GHI (it requires cleaning unnecessary "|" signs afterwards, but that's not a problem)

The problem is when we have two similar values, like "Name" and "First Name" in that case, if one field will contain "First Name" and the second one just "Name", the end result will be "First " instead of "First Name".

Any Ideas how to modify the formula to properly cover such cases as well?


11 REPLIES 11
caltang
17 - Castor
17 - Castor

Like so?

 

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
kwieto
8 - Asteroid

Unfortunately not. It works only if each value is different, but not if they are overlapping:Annotation 2025-04-24 153330.png

kwieto
8 - Asteroid

Interestingly, it will work if I first replace all spaces with other symbol, i.e. underscore ("_")
I tried that trick already, but without marking "\b" as you proposed, it didn't work

 

Annotation 2025-04-24 154044.png

caltang
17 - Castor
17 - Castor

Hmm @kwieto  what is the expected output then? Can you give a few scenarios?

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
kwieto
8 - Asteroid

OK, so the ultimate output should be like that:


Field 1Field 2 Field 1 != Field 2Field 2 != Field 1
Apple|Banana|OrangeApple|Banana|LemonOrange

Lemon

Apple|Red Apple|Apple Small|OrangeApple|BananaRed Apple|Apple Small|OrangeBanana
Apple|Green Apple|More Green Apple|Even More Green AppleMore Green Apple|Less Green AppleApple|Green Apple|Even More Green AppleLess Green Apple
Banana|Banana Rotten|Banana Rotten ExtremelyBanana|OrangeBanana Rotten|Banana Rotten ExtremelyOrange
caltang
17 - Castor
17 - Castor

I’ve tried a few ways but I wasn’t able to crack it (yet). The problem is if it exists and is not fully parsed in the 3rd and 4th columns… may need a few steps to get desired output rather than a direct regex I fear…

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Qiu
21 - Polaris
21 - Polaris

@kwieto @caltang 
Lets stop playing and use the Text to Column tool ðŸ˜‚

flying008
15 - Aurora

Hi, @kwieto 

 

As you want:

 

Spoiler
Replace(REGEX_Replace(Replace([Field 1],' ', '_'), '(\b' + Replace(Replace([Field 2],' ', '_'), '|', '(?:[^_])|\b') + '(?:[^_]))', ''), '_', ' ')

录制_2025_04_25_08_57_43_31.gif

Field 1Field 2Field 1 != Field 2Field 2 != Field 1
Apple|Banana|OrangeApple|Banana|LemonOrangeLemon
Apple|Red Apple|Apple Small|OrangeApple|BananaRed Apple|Apple Small|OrangeBanana
Apple|Green Apple|More Green Apple|Even More Green AppleMore Green Apple|Less Green AppleApple|Green Apple|Even More Green AppleLess Green Apple
Banana|Banana Rotten|Banana Rotten ExtremelyBanana|OrangeBanana Rotten|Banana Rotten ExtremelyOrange

 

 

 

caltang
17 - Castor
17 - Castor

Super cool!! Learned a new trick :)

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