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

Regex Replace

Tori_Isbell
5 - Atom

I'm trying to replace the single spaces (' ') between the dates with a double space ('  '). 

 

Job Number /   Cost       05/24/21 05/25/21 05/26/21 05/27/21 05/28/21 05/29/21 05/30/21

Description      Note       05/24/21 05/25/21 05/26/21 05/27/21 05/28/21 05/29/21 05/30/21      Reg.

 

 

I think using Regex Replace is the route to take, but I'm new to Regex functions so I'm not entirely sure. 

 

Any help is appreciated!

6 REPLIES 6
phottovy
13 - Pulsar
13 - Pulsar

Hi @Tori_Isbell ,

 

You can use either the standard "replace" or "regex_replace" to accomplish this change if every space will be replaced with a double space. If you are replacing the spaces in the original column, make sure your string length is long enough to include these additional spaces or else your column might get truncated:

 

Replace(string, ' ', '  ')

REGEX_Replace(string, ' ', '  ')

 

The regex_replace function will give you more options if you only need to replace spaces meeting certain criteria though.

Tori_Isbell
5 - Atom

Hi @phottovy,

 

All the data is in the same column. I need only the spaces between the dates to be adjusted, not every space. 

 

Do you have a suggestion on how the Regex_Replace should be written? I've tried many times and can't get it to work.

atcodedog05
22 - Nova
22 - Nova

Hi @Tori_Isbell 

 

You can use a regex_replace like this.

 

Workflow:

atcodedog05_0-1622563151360.png

 

here last digit of date is $1, space is $2, first digit of next date is $3. I am replacing original $1$2$3 with $1$2$2$3 basically repeating the space in between.

 

REGEX_Replace([Field1], "(\d)(\s)(\d)", "$1$2$2$3")

 

Hope this helps 🙂 

Mario36
8 - Asteroid

@Tori_Isbell 
Attached is my proposed solution. Let me know if that works.

phottovy
13 - Pulsar
13 - Pulsar

That makes more sense. Attached is a workflow that I believe accomplishes it. It uses the following RegEx:

 

REGEX_Replace([Example], '(/\d{2}) (\d{2}/)', '($1)  ($2)')

 

Here is a breakdown of the regex:

 

(/\d{2}) = look for "/" followed by two digits

(\d{2}/) = look for two digits followed by "/"

($1) = keep the original text in the first set of parentheses

($2) = keep the original text in the second set of parentheses

Tori_Isbell
5 - Atom

This works beautifully and cleanly! Thank you! 

Labels