Extract number from String
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you rags and datanath... this works perfectly, I'm fine with having only the first 7 digits pulled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Can you give more sample data? The more the merrier... Regex is heavily dependent on patterns, so let's see.
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Can you try this:
(\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.
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Yeap, this way works:
(\D*)(\d{7})(\D*)
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
