+ Reply to Thread
Results 1 to 5 of 5

RegEx for extracting 7 or 8 digit number only

  1. #1
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    RegEx for extracting 7 or 8 digit number only

    Hello

    Well, the title says it all. I have cells with text and a number. If this number is 7 or 8 digits long I wish to extract it, if it's shorter or longer I do not wish to extract it.

    There are no spaces between digits in a number.

    I struggle to make it exclude longer numbers.

    My current attempt:
    Please Login or Register  to view this content.
    Oh, maybe I should add, this is me learning RegEx. I could easily solve this with just VBA and no RegEx but today RegEx is on the menu.
    Attached Files Attached Files
    Last edited by Jacc; 08-15-2021 at 05:58 PM.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: RegEx for extracting 7 or 8 digit number only

    Try this. You do not need regout or x2.

    Please Login or Register  to view this content.
    Tested with your data.
    Last edited by 6StringJazzer; 08-15-2021 at 07:15 PM. Reason: fixed errors in code
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: RegEx for extracting 7 or 8 digit number only

    File attached
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: RegEx for extracting 7 or 8 digit number only

    If you also have data like
    1234567abc
    a12345678
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    Re: RegEx for extracting 7 or 8 digit number only

    Very impressive, thank you guys! RegEx code is hard to read for a novice but very cool!
    Jindon you are right, I do indeed have data like that. I should have put together better sample data.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extracting substrings using regex
    By gringol in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-07-2021, 11:40 AM
  2. Replies: 1
    Last Post: 03-02-2021, 12:09 AM
  3. [SOLVED] Pattern for regex that matches one digit at least
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-10-2018, 01:57 AM
  4. Extracting 9 digit number from text data
    By MHamid in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-08-2017, 02:14 PM
  5. Extracting 8 digit numeric number from an alphanumeric cell
    By chrisjack001 in forum Excel General
    Replies: 5
    Last Post: 11-21-2016, 01:54 PM
  6. Need help extracting data from web page source into excel using RegEx and macro
    By chococ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2014, 03:45 PM
  7. Replies: 7
    Last Post: 06-16-2011, 06:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1