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
Yeap, this way works:
(\D*)(\d{7})(\D*)
Nevermind, I've thought of something that incorporates REGEX and other tools as well:
Basically, we use Data Cleasning and REGEX to standardize your data, then use a length as filter to get what you want. Hope this helps @daniele_zatti
Kindly mark it as an accepted solution as well if it helped.
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.
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.
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
Thank you rags and datanath... this works perfectly, I'm fine with having only the first 7 digits pulled.
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?
Can you try this:
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.
string =====> desidered result
Forfeit 2674500 test 07/2023 =====> 2674500Singapore week 2 (2674502) =====> 2674502#2893429 rotation 4 test =====> 28934292909038 TRAINING =====> 29090382893310 ABCD2 JUNE23 MY =====> 2893310
In case you need my workflow, PFA. Hope this helps @daniele_zatti
Perfect, works smooth now!
Thank you SO MUCH! This was exactly the answer I needed to extract the first 5 digit number in a text string! Very helpful!