Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Extracting specific numbers using RegEx

adamhill3
7 - Meteor

Hi all,

 

I have been trying to get to grips with RegEx function but need some help. I have tried searching the wealth of content on here but couldn't manage to resolve this issue myself.

 

In short, I am seeking to extract a 10 digit number from a string of text only if it starts with one of 4 options:

 

- 61

- 62

- 71

- 72

 

I then want this result to come out in a new column which will be populated with all the new numbers

6 REPLIES 6
neilgallen
12 - Quasar
Doing from my phone so apologies if this isn’t perfect because I can’t test but I’ll get you going.

(61\d{8}|62\d{8}|71\d{8}|72{8})

The | is an “or”operator, where the \d{8} requires the pattern to have exactly 8 consecutive digits following the requested number sets.

Good luck!
JoshuaGostick
11 - Bolide

Hi adamhill3,

 

The attached workflow should hopefully work for you. Just to double check, is the output workspace supposed to be 9 digits and the output document supposed to be 10 digits?

 

Josh

adamhill3
7 - Meteor

@neilgallen wrote:
Doing from my phone so apologies if this isn’t perfect because I can’t test but I’ll get you going.

(61\d{8}|62\d{8}|71\d{8}|72{8})

The | is an “or”operator, where the \d{8} requires the pattern to have exactly 8 consecutive digits following the requested number sets.

Good luck!

Thank you for your response, much appreciated. This has worked really well but I still have some discrepancies which I am hoping you can help me with. I have been trying to resolve myself for 2 hours so sorry to ask you again.

 

I have attached a sample workbook again which shows two lines where the number is getting picked up, but also 2 lines where it is not and I cannot figure out why??

 

My only thought is that it is finding the 62 (WS962824690) towards the end of the string which does not meet the brief and then giving up?

adamhill3
7 - Meteor

@JoshuaGostick wrote:

Hi adamhill3,

 

The attached workflow should hopefully work for you. Just to double check, is the output workspace supposed to be 9 digits and the output document supposed to be 10 digits?

 

Josh


Hi Josh,

 

Thanks for this solution, really appreciate you taking the time. 

I have found in the data now that not al numbers are prefixed with an _ but I can't figure out how to remove the _ from your solution and it still work. Could you please help me out?

JoshuaGostick
11 - Bolide

Hi,

 

So I've changed the REGEX formula so that the numbers are extracted for not only just _ prefixes but for any non-numerical character. Also, it will extract the numbers if the text starts with one of the four numbers. Will this work for you?

 

Hope this helps!

adamhill3
7 - Meteor

@JoshuaGostick wrote:

Hi,

 

So I've changed the REGEX formula so that the numbers are extracted for not only just _ prefixes but for any non-numerical character. Also, it will extract the numbers if the text starts with one of the four numbers. Will this work for you?

 

Hope this helps!


Amazing! This is absolutely perfect. Don't think I would have ever got there on my own. Thanks so much

Labels
Top Solution Authors