Regex Replace
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Florin
This is not a normal replace this would require some prepping the data. Can you provide some sample data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
Please see below a snapshot.
I simply want to rename columns starting with F1 in ascending order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Florin ,
i'm not sure to get what you need but here is a workflow replacing "Field_" by "F" in all headers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
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 : )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Many thanks for support . That was exactly what I expected.
All the best,
Florin
