We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Extract the last two values from rows in text file with RegEx

45179902
8 - Asteroid

I have a text file with data like these:

 

ISP-123456    2    2    2    2

ASI-123213    2    3    1    5

PSI-123233    3    2    3    7

SRI-213232          1    4    9

SIR-122323    1    2   24   0

 

Suppose I want the last two values from each row (2 2, 1 5, 3 7, and 4 9), how can I achieve this? Note that these rows do not have the same number of column, but the values are always in the correct position. I'm thinking about a regular expression that will trim data starting with the second whitespace counting from the end of each row.

 

Update:

Thank you for the responses! But they remind me that I should be more clear with my question. Sorry for the incomplete example. I have added row five. As can be seen, the values can have more than one digit (24 0). In this case I still want the last two values of each row.

 

11 REPLIES 11
atcodedog05
22 - Nova
22 - Nova

Hi @45179902 

 

I was able to increase it to 4 digits above that position will anyways break. If provided there is a space in between n-digits of numbers this code will work.

 

atcodedog05_0-1642571713390.png

 

Hope this helps : )

 

OllieClarke
15 - Aurora
15 - Aurora

Hey @45179902 I had another go at this, and I think this works:

OllieClarke_0-1642588894433.png

Taking @atcodedog05's testing values, I think if you replace up to 5 spaces with a pipe (|) and then split to rows on that it should work, at least with the sample data you've given us. You might need to test on the full data to see if that max value of 5 is correct...

 

Ollie

 

Labels
Top Solution Authors