community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Remove All Special Characters Except for a few- RegEx

Highlighted

Hi Team,

 

I have an excel file with following data. I have 2 requirement as listed below.

 

Requirement 1 - There is a column "Special Characters" which has a few values. Requirement here is I except for $, I would like to remove rest all special characters from output. If there is some alphabet or numeral, then I could like to keep that as is. Please refer column "Expected Output - Requirement 1" in table below.

 

Requirement 2 -  Slight modification from the requirement 1. Except for $ and #, I would like to remove rest all special characters from output. If there is some alphabet or numeral, then I could like to keep that as is. Please refer column "Expected Output - Requirement 2" in table below.

 

I tried achieving this through RegEx tool, but could not. Any help in this regard is highly appreciated.

 

Thanks in advance.

 

Special CharactersExpected Output - Requirement 1Expected Output - Requirement 2
$%$%$$$$
%^%^  
&(*^(^  
#$%#&%&*$#$#
@$%#^56$56$#56
%&*&^  
123&*&123123
vsg45%#^vsg45vsg45#
ddfr66#ddfr66ddfr66#

 

Regards

Alteryx Certified Partner
Alteryx Certified Partner
Try using not in the list of characters as the replacement target.

Regex_replace([field],"[^a-zA-Z0-9\$]",'')

Cheers,

Mark

Ps. You can include other acceptable characters. Because $ is a reserved character I precede it by \. The # character can be added without concern.
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.

Thanks a ton for the quick response, Mark. This works for me.

Labels