Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

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

Regex Replace

Florin
6 - Meteoroid

Hi,

 

I am new in Alteryx and in writing expressions in Regex especially. I have the following situation for which I need your help:

I have a table header with many columns called : Field_4,Field_1,Field_10,.....Field_5...etc (randomly)

 

Using Regex Replace function I tried to rename those fields to F1,F2,F3....F9,F10...etc (ascending from left to right).

 

REGEX_Replace([_CurrentField_],"\<\w+\>" , "F")

 

The issue I have is that when reaches to 9, next field is replaced with "9_2" and so on.

Also "1" is missing in first renamed column.

 

Could you help me in fixing that?

 

Many thanks

 

6 REPLIES 6
atcodedog05
22 - Nova
22 - Nova

Hi @Florin 

 

This is not a normal replace this would require some prepping the data. Can you provide some sample data.

atcodedog05
22 - Nova
22 - Nova

Hi @Florin 

 

Can you provide snapshot of whats happening and some same data.

Florin
6 - Meteoroid

Hi,

Please see below a snapshot.

 

Florin_0-1627995079483.png

I simply want to rename columns starting with F1 in ascending order.  

Jean-Balteryx
16 - Nebula
16 - Nebula

Hi @Florin ,

 

i'm not sure to get what you need but here is a workflow replacing "Field_" by "F" in all headers.

atcodedog05
22 - Nova
22 - Nova

Hi @Florin 

 

You need a if else block to handle mutiple pattern.

 

Formula:

 

 

IF REGEX_Match([Name], "Field") THEN "F1" 
ELSEIF REGEX_Match([Name], "Field\d")  
THEN Replace([Name], "ield", "")
ELSE
"F"+ToString(
ToNumber(REGEX_Replace([Name], "Field(\d)_(\d)", "$1"))
+
ToNumber(REGEX_Replace([Name], "Field(\d)_(\d)", "$2"))-1)
ENDIF

 

 

 

Workflow:

atcodedog05_1-1627995420030.png

 

 

1st Condition: No number first column

2nd Condition: Only single number

3rd Condition: Number after nine 9_1

 

This should work in dynamic rename too.

 

Hope this helps : )

 

Florin
6 - Meteoroid

Many thanks for support . That was exactly what I expected.

 

All the best,

 

Florin

Labels