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

Extract the last symbols from a string

Rurikovich
5 - Atom

Hi all,

Recently I worked with Alteryx and the following question appeared:

How to extract the last symbols after the combination of “,” (coma and space)?

For instance, I have such rows:

 

1234 Metal, Wood, Containers, units
435792 Red bricks, t
38 Fresh Juice, aka Maracana, l

 

And I want to get the following column;

 

units
t
l

 

As you may have noticed, there are several combinations of “, “ in a string. However, their number may vary from 1 (the exact one before the units) to 4-5. So just splitting the text to columns using ", " does not help to create a column with a necesary data.
Could you please advise me, how it can be done?

 

Thanks

11 REPLIES 11
papalow
8 - Asteroid

@Rurikovich 

There is a way.  The attached workflow uses the RegEx tool.  You will want to parse the output and use the following expression:

 

[,]\s(\w+)$

 

papalow

jdunkerley79
ACE Emeritus
ACE Emeritus

You can also do this using a formula tool:

REGEX_Replace([Input], ".*(, )(.*)", "$2")

If you don't know regular expression there is also the option of doing it like:

Substring([Input],Length([Input])-FindString(ReverseString([Input]), " ,"))

Sample attached of both

Rurikovich
5 - Atom

Hi papalow,

 

Thank you for response, it worked but with some exceptions: 

 

Роутер TP-Link, шт

Болт крепления М10*45 S14, шт

5717270018, ПЕСОК КВАРЦЕВЫЙ, 0,1-0,3, кг

5717270018, ПЕСОК КВАРЦЕВЫЙ, 0,1-0,3, кг

Боты диэлектрические 5171, пар.

Боты диэлектрические 5171, пар.

 

These items, for instance (and some other as well) returned Null in the Regex output column. However, when I created an additional file with these items only the Regex worked almost fine (only the last two  returned Null instead of "пар."). Maybe you have an idea regarding this problem?

Rurikovich
5 - Atom

Hi, jdunkerley79

 

Thank you for your reply.

I tried both variants but they have returned only "??" or "???." etc. Perhaps it is due to the Cyrillic alphabet? The items are in Russian, for instance:

 

Роутер TP-Link, шт

Болт крепления М10*45 S14, шт

5717270018, ПЕСОК КВАРЦЕВЫЙ, 0,1-0,3, кг

5717270018, ПЕСОК КВАРЦЕВЫЙ, 0,1-0,3, кг

Боты диэлектрические 5171, пар.

Боты диэлектрические 5171, пар.

 

Could you please advise how the formula can be upgraded in this context? 

jdunkerley79
ACE Emeritus
ACE Emeritus
Regex replace - but then I love Regular Expressions (my team hates me for them).

I expect performance of reverse find might be faster but generally wouldn’t be stressing over that level of optimisation and if I was would want to implement a true FindLast implementation.

James
Rurikovich
5 - Atom

It has worked perfectly, thanks a lot!

papalow
8 - Asteroid

@Rurikovich 

The last 2 items have a punctuation mark.  You could insert a RegEx tool into the workflow to remove the punctuation on the last character.  The output method would be replace.  The regular expression would be [.]$.  

papalow
8 - Asteroid

@jdunkerley79 

Thanks for providing your second solution -- it is one I hadn't thought of.  

jdunkerley79
ACE Emeritus
ACE Emeritus

It was erroring as I had chosen V_String (ASCII only) as opposed to V_WString (Unicode) in the formula tool.

 

Update sample attached.

Labels