How to use a field using regex for the condition like:
field A can have only - and () special characters
Solved! Go to Solution.
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
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
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
actually i need to check for phone numbers which can have digits and - and () as special characters.
REGEX_MATCH([Field1],'[\d\-\(\)]+') will only match fields comprised of digits and -()
Hello @simran2003,
Then you can use this:
REGEX_Match([Field1], '[\d\-\(\)]*')
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Regards
It worked.Thanks a lot.