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

Problem with regex formula

NiccoloPardelli
6 - Meteoroid

Hi everyone!

I am currently experiencing problems with Regex formula. 

I want to remove the symbols :*][/\? and I am using the formula since the Data Cleansing tool seems blocking my app.

Currently the formula looks like this:

regex_replace([#1],"\s","") AND
regex_replace([#1],"\","") AND
regex_replace([#1],"/","") AND
regex_replace([#1],":","") AND
regex_replace([#1],"?","") AND
regex_replace([#1],"*","") AND
regex_replace([#1],"[","") AND
regex_replace([#1],"]","")

The problem is that it is not removing the characters but substituting the whole string with two 0.

Do you know how to solve this?

Many thanks!

5 REPLIES 5
BenMoss
ACE Emeritus
ACE Emeritus

REGEX_REPLACE([Field],'[[:punct:]]','')

 

Should do the job (note this is all punctuation), is this what you want? I ripped this directly out of the data cleansing tool as it it as a macro.

 

Ben

BenMoss
ACE Emeritus
ACE Emeritus

regex_replace([_CurrentField_],"\s|\\|/|\:|\?|\*|\[|\]","")

 

will also work. | acts as an 'or'

 

and you must escape special characters with a \ in regex.

Jim7
8 - Asteroid

You're running into issues because several of the characters you're trying to replace are special characters. In addition to escaping the space (\s), you should escape the other special characters:

 

\[

\*

\\

\?

danrh
13 - Pulsar

Another option:

REGEX_Replace([Field1], '[\:\*\]\[/\\\?]', '') 

 

NiccoloPardelli
6 - Meteoroid

It worked! Many thanks for the explanation

Labels