+ Reply to Thread
Results 1 to 29 of 29

Generate unique numbers according to specific regex pattern

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Generate unique numbers according to specific regex pattern

    Hello everyone
    I have the following regex pattern
    Please Login or Register  to view this content.
    You can test on this link
    https://regex101.com/r/4et8ee/1

    I need to generate valid numbers according to this regex pattern randomly and unique ..
    Thanks advanced for help
    Regards
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  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: Generate unique numbers according to specific regex pattern

    I see something in this pattern that could be a bug and I want to make sure it is not.

    Please Login or Register  to view this content.
    [0-38] means "a digit that is either in the range 0-3, or the digit 8"

    If you mean "a number from 0 to 38" then this is wrong.

    Can you confirm this part of your expression is correct?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Thanks a lot for reply
    Yes it is correct as you explain .. I have updated the regex pattern again
    Please Login or Register  to view this content.
    at this link
    https://regex101.com/r/4et8ee/7
    Last edited by YasserKhalil; 08-10-2018 at 09:35 AM.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    To explain the pattern .. this is national ID that is of length of 14
    The first digit should be either 2 or 3
    The second and third digit is for year so 00 - 01 - 02 - ......... - 99
    The fourth and fifth digits for month so 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 -09 -10 - 11 - 12
    The sixth and seventh for days so 01 - 03 - ............ 31
    The eighth and ninth for district and they are not fixed .. they are : 01 to 04 and 11 to 19 and 21 to 28 and 31 to 36 and 88
    The last 5 digits are random

  5. #5
    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: Generate unique numbers according to specific regex pattern

    I developed an entire solution based on your first pattern and now you have completely changed it. Here is what I did. Hopefully you can modify this for your new pattern. Best of luck.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Thanks a lot for great help
    In fact that's great solution but I have to deal with each digit separately .. I imagined that using regex pattern can be read in random way so as to generate those numbers
    Generally I will try to modify to suit the new pattern
    Thank you very much

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    I tried to modify but I am lost although the logic seems simple .. Can you help me with the new regex pattern?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Any help in this topic please?

  9. #9
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Generate unique numbers according to specific regex pattern

    For generate number
    Please Login or Register  to view this content.
    For matching string
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    That's great ikboy. Thanks a lot for great and awesome help
    I have modified that as it is very clear .. Thanks a lot
    Best Regards

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Won't that generate dates that include Feb 30th and Feb 31st?
    Entia non sunt multiplicanda sine necessitate

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Another way:

    Please Login or Register  to view this content.
    Last edited by shg; 08-12-2018 at 07:38 PM.

  13. #13
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Generate unique numbers according to specific regex pattern

    shg,
    u right
    Many ways can do it
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Thanks a lot for those valuable replies
    @shg :: I got a random ID like that
    28810130036370

    00 is not acceptable .. will I remove 0 from the variable sDist to adjust. .?? and in this case the number 30 will be 29 in this part
    Please Login or Register  to view this content.
    * last note what If I want to exclude 0 from the last digit .. I mean instead of 0 in the example generated 28810130036370 >> to generate numbers from 1 to 9 and not zero

    Thanks a lot for great help

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    After so much time I could figure it out
    Please Login or Register  to view this content.
    Thanks a lot for your great and awesome help for all of you

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Just one remaining point in this topic ..
    As for the first digit 2 or 3 .. should be related to the years .. That's in last code from 1980 to 2020
    It is supposed that 2 is related to 1900 to 1999 and 3 is related to 2000 to 2099 .. How can I adjust the UDF to get the desired digit according to the year?

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Quote Originally Posted by YasserKhalil View Post
    After so much time I could figure it out
    Please Login or Register  to view this content.
    Since the number encodes year as two digits, extending DOB past the turn of the century only serves to double the likelihood of years 00 to 19.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    I am sorry I can't get what you mean ..

  19. #19
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    In what century was someone born if their date code is 000101?

  20. #20
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    According to the start and end dates .. 00 means 2000 as 19 means from 1980 to 1999 (this would be 2 as first digit)
    and from 2000 to 2020 would be 3 as first digit ... so the start date and end date would determine the proper century ..

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Hope it is so clear sir

  22. #22
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Please Login or Register  to view this content.

  23. #23
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Thanks a lot for your great help
    In fact I am lost a little .. The constants that determines start date and end date was perfect for me .. and now in results I found 38410232147697
    which is not correct as 1984 related to 2 ...
    Can post # 15 be please edited to modify the 2 or 3 but to keep the start and end dates ..?

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Sorry ...

    Please Login or Register  to view this content.

  25. #25
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    So what is the start date and end date ...
    Is #12/21/1999# right or #12/31/1999# ??
    Can start date and end date be constants as in post #15?

  26. #26
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    The dates of birth vary randomly over the last 100 years.

  27. #27
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    Quote Originally Posted by shg View Post
    The dates of birth vary randomly over the last 100 years.
    Is that a problem in dealing with the code? .. Post # 15 is the most suitable for me till now
    Just the first digit .. I would use a line at the end of the UDF that determines 2 or 3 according to the yy (year)
    Thanks a lot for great help

  28. #28
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate unique numbers according to specific regex pattern

    Please Login or Register  to view this content.

  29. #29
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate unique numbers according to specific regex pattern

    That's perfect and awesome now. Thank you very very very much for great help and thanks a lot for your patience
    Best Regards

+ 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] Regex pattern for specific date format
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2018, 10:14 AM
  2. RegEx - Pattern Matching
    By paularthur90 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2017, 09:16 AM
  3. Need to Define RegEx pattern
    By hmr2662 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2015, 09:24 AM
  4. RegEx pattern
    By capson in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-15-2015, 06:57 PM
  5. [SOLVED] RegEx pattern, code exacuting but doing nothing
    By capson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2015, 03:48 PM
  6. Regex - establishing a pattern
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-30-2014, 11:06 AM
  7. Need a new regex .pattern for comparison code
    By Swiss Cheese in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-06-2012, 09:16 PM

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