Alteryx Designer Desktop Discussions

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

Regex: Replacing space with "-"

MosesAddai24
7 - Meteor

I am trying to replace “ “ and “/” in this column with “_” . How do I frame the regular expression and replacement text?

9 REPLIES 9
JoaoLeiteV
10 - Fireball

Hello @MosesAddai24,

 

The images you posted aren't already doing that? The Original Header(State) seems to have, for example, the text "2 3", and you're replacing the text.

 

If not, if your data is composed of digits and words, you can use ([\w\d]+)[\s\/]([\w\d]+)

 

This will:

   1. ([\w\d]+) - Group any combination of words and digits

   2. [\s\/] - Check if theres a spacebar of a slash

   3. ([\w\d]+) - Group again any combination of words and digits

 

Then for the replacement, just use "$1_$2"

 

JoaoLeiteV_0-1626812588970.png

 

 

Hope this helps!

Hi @MosesAddai24 

 

This is a Non-Regex way that uses formula to achieve the same goal. Hope it helps. Cheers!

 

christine_assaad_0-1626812997775.png

 

MosesAddai24
7 - Meteor

I tried it and got an error that says " " cannot be found. How do solve the error?

MosesAddai24
7 - Meteor

When I used that I got **_** throughout that column. Do I have to change something in the code?

KarolinaRoza
11 - Bolide

hi @MosesAddai24 

 

I just tried to replace any white space and slash signs using:  [\s\/] in Regular Expression with "_".  It should work.

 

Karolina

KarolinaRoza_1-1626813912540.png

 

 

MosesAddai24
7 - Meteor

It worked! Thank you !

apathetichell
18 - Pollux

@JoaoLeiteVFYI - \w includes \d already so no need to check for both...

JoaoLeiteV
10 - Fireball

Thanks for the tip @apathetichell! I'll keep that in mind.

Hi @MosesAddai24 

 

I'm glad you were able to get your problem solved, from the screenshot, it seems that you did not give your newly created column a name, hence the error. Cheers!

Labels