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

Unable to use regex

simran2003
7 - Meteor

How to use a field using regex for the condition like:

field A  can have only - and () special characters

7 REPLIES 7
afv2688
16 - Nebula
16 - Nebula

Hello @simran2003,

 

Using this formula

 

REGEX_Replace([Field1], '[^\u_\-_\(_\)_\d]', '')

 

Will give you back only letters, numbers and the special characters you mentioned. If you want to add spaces too:

 

REGEX_Replace([Field1], '[^\u_\-_\(_\)_\d_\s]', '')

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Regards

simran2003
7 - Meteor

I want to check if the field1 of type double has only - and () as special characters.This code you provided is n't working for it.@afv2688

afv2688
16 - Nebula
16 - Nebula

Hello @simran2003,

 

What you are asking doesn't make any sense to me. Double fileds can only have numbers, therefore they can only have digits, dash to indicate negative numbers and dots for the decimals.

 

I am aware that in finance sometimes you use the parenthesis to indicate negative numbers, but alteryx does recognize it and change them to negative values.

 

There is no way a number will have parenthesis they way they are displayed on the result window being numbers.

 

Anyways, if it was a string, you could use to look for them the following formula:

 

 

REGEX_Match([Field1], '(.*)?\-(.*)?') OR REGEX_Match([Field1], '(.*)?\((.*)?\)(.*)?') 

 

 

Which will look for "-", "(", ")"

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Regards

simran2003
7 - Meteor

actually i need to check for phone numbers which can have digits and - and () as special characters.

OllieClarke
15 - Aurora
15 - Aurora

REGEX_MATCH([Field1],'[\d\-\(\)]+') will only match fields comprised of digits and -()

afv2688
16 - Nebula
16 - Nebula

Hello @simran2003,

 

Then you can use this:

 

REGEX_Match([Field1], '[\d\-\(\)]*')

 

Untitled.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Regards

simran2003
7 - Meteor

It worked.Thanks a lot.

Labels