Welcome to the Alteryx Knowledge Base
Created/Edited -
Let's say you have data like this and you'd like to remove the numbers at the end:
Blue4509
Yellow2345
Orange2315
Blue6754
You could useLeft(x, len), like this:left([Data], (length([Data]) - 4))
(This calculates the length of the field, subtracts 4 and then takes that many characters from the left. E.g.: length(Blue4509) = 8, 8-4 = 4, left(Blue4509,4) = Blue)
Ora combination ofReverseString(Str) andSubstring(x, start, length):ReverseString(substring(ReverseString([Data]),4,100))
(This reverses the string, uses a substring to start at the 5th position [positions are zero based], takes the next 100 characters, and then reverses it back. E.g.: reversestring(Blue4509) = 9054eulB, 5th position = e, next 100 characters = eulB, reversing it back results in Blue)
BUT what if your data looks like this:
Blue4509
Yellow2345
Orange231
Blue6754
Green596828
The above won't work anymore, but ReplaceChar(x, y, z) will:replacechar([Data], '0123456789','')
(ReplaceChar(x,y,z)returns the string [x] after replacing each occurrence of the character [y] with the character [z].)
OrRegex_Replace(string, pattern, replace,icase):regex_replace([Data],"\d","")
(Regex_Replace(string, pattern, replace,icase) returns the string after replacing the pattern with the replace. In this case, it replaces all digits.)
Or the Regex Tool:
\d in regular expression identifies digits (aka numbers)
What if your data looks like this:
1Blue4509
2Yellow2345
3Orange231
4Blue6754
5Green596828
and you want to preserve the number at the beginning of the string but remove the ones at the end?
The $ character in regex denotes the end of the string, * identifies one or more instances of the preceding character,so \d*$ identifies one or more digits at the end of the string:regex_replace([Data], "\d*$","") or:
Also, check out all the other functions on the Alteryx help page,POSIX Extended Regular Expression Syntax, more info on the Regex Tool, and the Regex Cheat Sheet on the community.