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

Extracting data using RegEx

Q_Ball
7 - Meteor

Hi all,

Wonder if anyone can help, I have a text string P88228#UK-ORG#10R1 that I want to extract from two pieces of data.
1. All the data in front of the # (po number) 

2. The line number which is after the second # but only upto and not including the 'R'

Any help would be appreciated.

 

Thanks

8 REPLIES 8
Kenda
16 - Nebula
16 - Nebula

Hey @Q_Ball! I would recommend using a Formula tool. I would first create a new field for po number with this expression:

REGEX_Replace([Field1], "(.*?)\#.*", "$1")

This will extract P88228.

 

Then, I would create a second field for your line number with this expression:

REGEX_Replace([Field1], ".*\#(.*)R.*", "$1")

You will get you 10. This assumes that you will always want the cut off for the line number to occur after the last hashtag and before the R. Hope this helps!

MarqueeCrew
20 - Arcturus
20 - Arcturus

Hi @Q_Ball,

 

Here is one formula that gives you a delimited answer.  These parts can easily be parsed into separate fields.

 

Regex_REPLACE([Field],"^(.*?)#.*#(\d+)R.*",'$1|$2')

It will find:

 

^      Beginning of field

.*?    Anything up to the first # symbol

(\d+)  Whatever numbers are between the # symbol and the R

 

Groups found are the stuff between the parens....

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Q_Ball
7 - Meteor

Hi            

the second part doesn't quite work and brings back EVN-O

MSalvage
11 - Bolide

@Q_Ball,

 

This might be a little low tech, but I would just use 2 Text to Columns tools. one with # as the delimiter with 3 output columns. Using the second on the column with 10R1 in it with R as the delimiter. Unless that letter changes... In which case you could use a regex tool set to parse. Ex attached.

 

Best,

MSalvage

Kenda
16 - Nebula
16 - Nebula

@Q_Ball Could you provide the original string that you used the formula on to get that result? I assume it is different than the one you provided initially as that one does not have "EVN-O" in it at all. 

Q_Ball
7 - Meteor

@BarnesK
My fault as sometimes there isn't an R in the data and it just has the order line number ... see example  P50208#EVN-ORG#10
Is there a way of getting the line in both scenarios?

Kenda
16 - Nebula
16 - Nebula

@Q_Ball Try this instead of the other formula for the line number:

REGEX_Replace([Field1], ".*\#(\d+).*", "$1")

It works for me for the two examples you have provided.

Q_Ball
7 - Meteor

@BarnesK

 

Works perfectly .. thanks for taking the time out to help me.

 

Q

 

Labels