Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Extract Last Character in a String

bsolove
8 - Asteroid

I want to isolate the last character in a string in a separate column if it is a letter.  I've tried several things with no luck.  The string field length varies.

4 REPLIES 4
JosephSerpis
17 - Castor
17 - Castor

Can you use the function Right(field,1)? I mocked up a quick example and used a regex tool you can also do this within the formula tool and replace and digits so you are left with only letters.

 

Regex_031219.PNG

fmvizcaino
17 - Castor
17 - Castor

Hi @bsolove ,

 

You can use regex to achieve that. Look at the attached example.

 

Let me know if that works for you.

Best,

Fernando Vizcaino

CharlieS
17 - Castor
17 - Castor

To only return that character when it is a letter, I used and IF statement with a RegEx_Match( function. Here's an example where the field tested is "String":

 

IF REGEX_Match(LowerCase(Right([String],1)),"\l") THEN Right([String],1)
ELSE null() ENDIF

 

This expression will return a null value if the field does not end in a letter. 

 

Expression Breakdown:

- Take the last character of the string using "Right([String],1)"

- Force that to lowercase (when applicable) using "LowerCase("

- Use RegEx to test if that character is a lower case letter using "REGEX_Match(" and "\l".

- When that condition is true (the last letter is a lower case letter) then return that last character in the original form using "THEN Right([String],1)"

- Otherwise, return a null result using "nuil()"

Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @bsolove,

 

I would take a slightly different approach and use one regex tool to parse out the last letter. I've used (\l|\u)$ as my regex formula, however since i have the "case insensitivity" box checked i could use (\l)$ or (\u)$ but if you need to keep it case sensitive (and un-check the box) the original regex formula of (\l|\u)$ would suffice.

 

image.png

 

If this solves your issue please mark the answer as correct, if not let me know! I've attached my workflow for you to download if needed.

 

Regards,

Jonathan

Labels