community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Upgrade Alteryx Designer in 10 Steps

Debating whether or not to upgrade to the latest version of Alteryx Designer?

LEARN MORE

Dynamic regex replace and returning what was found

Meteoroid

If I want to apply a large set of regular expressions to search and replace in every row of data, @patrick_digan's solution to this query works well.

 

I was trying to extend the macro to allow some extra functionality. Imagine that the regex specification file contained the following lines:

 

param  replace tag
\d{5}  XXX     digital
apple  pear    fruit

 

Based on user selection (a drop down menu?) do one of the following:

 

1. search and replace as usual 

 

For input data string "life is a 555 apple", the above rules will result in output string "life is a XXX pear"

 

2. if regex matches, then return the specified tag. 

 

For input data string "life is a 555 apple", the above rules will return "digital,fruit" (delimited by ',')

 

3. if regex matches, then return the part of the data string that matched

 

For input data string "life is a 555 apple", the above rules will return "555,apple" (delimited by ',')

 

If more than one regex matches, then the tags or found substrings need to be concatenated with some delimiter  (e.g. comma - which could also be user-specified)

 

I attach patrick_digan's macro. Please advise.

 

Thanks

Quasar

Hi @Fnold 

 

I think we do not need to build a macro. A combination of append, multiple-row formula, sort and sample tools can achieve requirement #1 while a combination of append, formula and summarise tools can achieve requirement #2 and #3:

 

Capture.PNG

Meteoroid

This is very impressive - I didn't consider the multi-row formula to accumulate regex search/replace. 

 

I'll test this out some more. Thanks very much.

Labels