Regex IF match then replace only second capturing group
- 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 community! I have a question - can I use the formula tool to do :
- a regex match to match my two capturing groups
- then, if my second capturing group is x, replace it with y
I can do it via multiple steps, but I'm eager to do it in fewer steps if possible.
So my data looks like this
202104
202105
202106
What I want is to change this column to read
2021-Monday
2021-Tuesday
2021-Wednesday
So I want to keep the first four digits i.e. the first capturing group, and then replace the second capturing group by saying IF 04 then Monday, IF 05 then Tuesday, IF 06 then Wednesday etc. I've used this expression
IF REGEX_Match([Period], "(\d){4}(04)") then "Monday" elseif
IF REGEX_Match([Period], "(\d){4}(05)") then "Tuesday" etc
And then via multiple steps I get to my desired format.
Is there any way to get to my output in fewer steps?!
Hope this makes sense and thanks for any tips!
Solved! Go to Solution.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi, I can probably help!
I just want to understand, why does 04 map to Monday, 05 to Tuesday. 06 to Wednesday?
- 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
@BS_THE_ANALYST my understanding was 202104 : 2021-01-04 which is Monday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@binuacs, @Felipe_Ribeir0 , and @FinnCharlton thank you both! All three perfect solutions that worked, I've accepted them all, just to say that I think I'll be going with @Felipe_Ribeir0 as I had never used 'switch' before and it was cool to use it :)
And of course you are right that I didn't need regex to do this (although I enjoyed the riddle of trying to do it with one single regex formula)
Cheers all!
