Alteryx Designer Desktop Discussions

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

Extract number from String

daniele_zatti
6 - Meteoroid

Hi - I'm looking to extract from a string any 7-digit number sequence using RegEx.

 

Here are two example:

 

TEST 1234567 1608-3108                       ==>          1234567

 

TEST22 MOD.6_7894561_JUNE 23'       ==>         7894561

 

Thanks,
Daniele

15 REPLIES 15
Rags1982
10 - Fireball

Regex would be the go to option here. 

Something like this I think :

.*(\d{7}).*

Use this in a regex tool, or formula. There's also www.regex101.com which is a great help. 

DataNath
17 - Castor

Hey @daniele_zatti, I think if you wanted this to be truly specific to only 7-digit patterns then you'd want to use something like:

 

 

.*\D(\d{7})\D.*

 

 

In the RegEx tool in Parse mode.

 

@Rags1982 I originally thought something like that would be fine, but if you test the following string for example:

 

test 1234555 12352349843983 TEST

 

.*(\d{7}).* returns 9843983, rather than 1234555.

Rags1982
10 - Fireball

Ah, @DataNath , very true.
I guess it depends on whether there are definitely non digits before where the 7 digit number is, like your example. 

One thing I always struggled with was repeating strings. So, in your example, How would you bring back BOTH 7 digit numbers? So, 1234555 AND 9843983

daniele_zatti
6 - Meteoroid

Thank you rags and datanath... this works perfectly, I'm fine with having only the first 7 digits pulled.

daniele_zatti
6 - Meteoroid

Datanath, I was just checking again, but this seems not to work with the 7 digits are at the very beginning of the string... any suggestions?

caltang
17 - Castor
17 - Castor

Can you give more sample data? The more the merrier... Regex is heavily dependent on patterns, so let's see.

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
caltang
17 - Castor
17 - Castor

Can you try this: 

image.png

 

(\D*)(\d{7})(\D*)

 

I modified @DataNath's solution a bit.

 

Anything that gets you the 7 digits - from there you need to prep your way to get each 7 digits. 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
daniele_zatti
6 - Meteoroid

string =====> desidered result


Forfeit 2674500 test 07/2023 =====> 2674500
Singapore week 2 (2674502) =====> 2674502
#2893429 rotation 4 test =====> 2893429
2909038 TRAINING =====> 2909038
2893310 ABCD2 JUNE23 MY =====> 2893310

caltang
17 - Castor
17 - Castor

Yeap, this way works:

image.png

 

(\D*)(\d{7})(\D*)

 

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Labels