Start Free Trial

Alteryx Designer Desktop Discussions

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

Regex with pattern variations

hellyars
13 - Pulsar

I have a REGEX question.

I am trying to isolate a CODE and AMOUNT from an original RAW_TEXT field.

 

I thought my data conformed to LN#1 where the CODE always came after a "|" and the amount always started with a $, but that turned out not to be the case.  LNs 1-5 show the different variants I have encountered.  The code that always starts with "0" and 4 alpha-numeric characters is always followed by the amount.

 

So far I have tried the following REGEX, but it does not account for all scenarios or the pesky "," in that may or may not appear in the amount.

 

 

^.*?(\|0.{4}|0.{4})\s(\d+$|\$\d+)

 

 

LN
RAW_TEXTCODE (Desired Output)AMOUNT (Desired Output)
1Smoked Colored Plastic, Mounted on Hood|09WAD $32709WAD327
2Located in Steering Wheel 08XHW $2808XHW28
3for Marker Lights and Headlights, Located in 08XHX $2,80008XHX2800
4for Sound Abatement|09HAN 16709HAN167
5Stationary, Painted Grille & Headlight Bezels|09HAT 22CR09HAT22
5 REPLIES 5
Qiu
21 - Polaris
21 - Polaris

@hellyars 
For your exact input. 😁

0301-hellyars-1.PNG0301-hellyars-2.PNG

hellyars
13 - Pulsar

@Qiu  I left out one variation.  CODE can also be all numbers, such as 08781.  How do I adjust for that? 

Qiu
21 - Polaris
21 - Polaris

@hellyars 
It will still work.

Since \d is also part of \w.

0301-hellyars-3.PNG

TheOC
16 - Nebula
16 - Nebula

hey @hellyars @Qiu 

Thought i'd drop a hacky solution into the mix - just to cause a bit of a stir 😁

 

TheOC_0-1646091718726.png

 

 

I just use Getword, and count words, to get the last two words isolated. Replacing Pipe with a space prior. 

I would just need to tidy up the results with some data cleansing, but the words you needed isolating are isolated. 

Hopefully this helps at all,
TheOC

Cheers,
TheOC
Connect with me:
LinkedIn Bulien
hellyars
13 - Pulsar

@TheOC  Cool, but this also works on the thousands of lines I want to ignore. That said, I wan to keep this in the toolbox.  Thanks.

Labels
Top Solution Authors