Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Stripping leading zeros then putting them back with RegEx

NAC
6 - Meteoroid

I have a column of V_strings called Code. The values all start with zeros. I need to remove the leading zeros then put them back later on. If I use TrimLeft([Code],"0") it does trim the zeros but I loose count of how many zeros I had. My plan is to put the zeros in another column to concatenate them back later. For example:

 

000123F-001          ------->          000  +  123F-001          --------->          000123F-001

 

I'm pretty sure I have to use a RegEx to do this but after playing with various regular expressions it seems I can't find which one works. My guess to extract the leading zeros is something like this:

 

REGEX_Replace([Code],"(^0+)[!0]\w+","$1")

 

But it does not work.

Any help is appreciated.

2 REPLIES 2
seinchyiwoo
Alteryx Alumni (Retired)

What about using the following expression in your Regex?

seinchyiwoo_0-1594171759701.png

 

This is what I've got as a result:

seinchyiwoo_1-1594171779215.png

 

 

Cheers,

Seinchyi

 

AbhilashR
15 - Aurora
15 - Aurora

Hi @NAC@seinchyiwoo has already provided a solution but wanted to propose a non-regex approach if you were curious.

 

AbhilashR_0-1594177175584.png

You could add back the leading 0's with padleft ([NEW_FIELD], [COUNT_ZERO],'0')

Labels