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

Regex Parse from the "right"

bmalak_98
6 - Meteoroid
Hello. I'm parsing some strings into component parts using the Alteryx RegEx node. I'd like to use a single formula to find the "parsing" characters from the "end of string." I could build a formula with if...then...else, reverse, and regex functions, but think this could be done with node.
 
In the last two rows of the table below, there are two instances of one of the parsing characters, "X".  I'd like to use the "last" instance of that value, or "from the right."  The character string lengths in front of or behind the parsing character could be variant lengths, so specifying the number of characters to look for is not a preferred solution.  
 
My current formula is
 
(-|X|D|R)(.*)
 
 
StringRegExOut1RegExOut2
195/75D14D14
7-14.5-14.5
7.00-14-14
7.00-14-14
7.50-15-15
7.50-17-17
10.5/80-18-18
10/10.5-20-20
1050/50R32R32
10X61X5X61X5
10X9X100X9X100
 
But would like to get the portion that follows the "last" instance of the "X" character.  
 
Desired
RegExOut1RegExOut2
D14
-14.5
-14
-14
-15
-17
-18
-20
R32
X5
X100
 
These attempts return NULLs.
Returns NULLs:\>(-|X|D|R)(.*)
Returns NULLs:(-|\>X|D|R)(.*)
 
Any ideas? Thank you.
8 REPLIES 8
Pang_Hee_Choy
12 - Quasar

if the second part always is number. you can try to use [\d\.] (any character is number or dot) and $ (refer to the end of the string)

 

(-|X|D|R)([\d.]+)$

 

Pang_Hee_Choy_1-1637113246607.png

 

cmcclellan
13 - Pulsar

This will give you 3 fields, but does what you want to do 🙂 

 

 

(-|X|D|R)(?!.*(-|X|D|R))(.*)$

 

cmcclellan_0-1637113760435.png

 

Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @bmalak_98,

 

You could use something along these lines:

 

.*?([a-z])?([\d\.]+)$

 

The dollar sign anchors the regex to the end of the string so you're searching for the last iteration of a character a-z (which could or may not be there) followed by the last number (including decimal places)

 

JonathanSherman_0-1637156157463.png

 

I've attached my workflow for you to download if needed!

 

Kind regards,

Jonathan

 

bmalak_98
6 - Meteoroid

Thank you, @Pang_Hee_Choy.

 

That works well.  

bmalak_98
6 - Meteoroid

Thank you, @cmcclellan.

 

I can use that as a solution.  

bmalak_98
6 - Meteoroid

Thank you, @Jonathan-Sherman 

 

That works great. 

 

I've incorporated bits and pieces from all the responses so far and have settled on the 

 

(-|X|D|R)([\d.]+)$

Pang_Hee_Choy
12 - Quasar

@bmalak_98 

 

just in case the number is more than 1000 and have thousand separator (,).

 

you may add a comma in the [\d.]

 

(-|X|D|R)([\d.,]+)$

 

Pang_Hee_Choy_0-1637212034763.png

 

bmalak_98
6 - Meteoroid

Thank you for the update.

Labels