+ Reply to Thread
Results 1 to 22 of 22

Pattern for regex that matches one digit at least

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

    Pattern for regex that matches one digit at least

    Hello everyone
    I am searching for a way to type a pattern that matches 9 length of letters and numbers ...but at least must have a digit at least
    I have used this

    Please Login or Register  to view this content.
    But if the word is of 9 letters only it matches and I don't want to match that because there is no digits at all in this case
    so
    123456789 is acceptable
    and 125AYH6AX is acceptable
    but AbcDEFghI is not acceptable

    The thread is posted also at this link
    http://www.eileenslounge.com/viewtopic.php?f=27&t=30522
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Pattern for regex that matches one digit at least

    IIRC the usual way is to add (?=.*\d) to the start of the pattern. I can’t recall if this works in VBA/VBS.

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

    Re: Pattern for regex that matches one digit at least

    Thanks a lot for reply
    I tried your suggestion and it is the same problem with the strings with 9 length and all letters
    Please Login or Register  to view this content.

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

    Re: Pattern for regex that matches one digit at least

    Why make it so complex?
    Please Login or Register  to view this content.

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

    Re: Pattern for regex that matches one digit at least

    Thanks a lot Mr. Jindon
    I don't make anything complex at all .. I am searching for a pattern for what I have described not a VBA code now
    In VBA you solve it in a great approach but what about the pattern ..? Will it be impossible
    I tried
    Please Login or Register  to view this content.
    and that is semi-perfect .. Just want to exclude those that has 9 letters >> if it is impossible just tell me

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

    Re: Pattern for regex that matches one digit at least

    Not in one line AFAIK.

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

    Re: Pattern for regex that matches one digit at least

    Thanks a lot for your great help. Your code is great and I will make use of it certainly

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Pattern for regex that matches one digit at least

    It works for me - I just tested it. What's your code that fails, and what is the input?

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

    Re: Pattern for regex that matches one digit at least

    Have a look at this link ..
    https://regex101.com/r/3Rgp9Q/1

    the strings 'AAAAAAAAA' and 'ABCDEBATX' needed to be excluded .. using the pattern

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Pattern for regex that matches one digit at least

    Like I said, it works for me, so what is the code you are using?

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

    Re: Pattern for regex that matches one digit at least

    Sir I am not searching for a code. I can adopt Mr. Jindon's part in the code .. I am searching for a suitable pattern but it seems impossible for regex patterns to suit that !!!

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Pattern for regex that matches one digit at least

    Once more for luck. It works for me. Adding that pattern to your link then entering either of those, no matches are found.

    And if you aren't searching for a code, why have you posted in the VBA programming section?
    Last edited by rorya; 08-09-2018 at 04:27 AM.

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

    Re: Pattern for regex that matches one digit at least

    rory's pattern is working and should be
    Please Login or Register  to view this content.
    first time for me to shortest match within brackets.
    Thanks rory.

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

    Re: Pattern for regex that matches one digit at least

    @Jindon
    Have you looked at the link in post #9 to see if that matches ..?
    @rorya
    I don't know forums that discuss regular expressions and it is related somewhat to VBA,isn't it?

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

    Re: Pattern for regex that matches one digit at least

    Please Login or Register  to view this content.

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

    Re: Pattern for regex that matches one digit at least

    Thanks a lot ikboy for reply
    Can you test your pattern on the link in post #9 please?

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

    Re: Pattern for regex that matches one digit at least

    Please Login or Register  to view this content.

  18. #18
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Pattern for regex that matches one digit at least

    Just to be clear, I tested that pattern on your link and it correctly rejected both of your all text entries.

  19. #19
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Pattern for regex that matches one digit at least

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

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

    Re: Pattern for regex that matches one digit at least

    Thank you very very much Mr. Karedog
    You are super star. Exactly as I was searching for

    I tried to read the explanation on regex101 but I couldn't get it well ...Generally it is perfect

  21. #21
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Pattern for regex that matches one digit at least

    You are welcome.
    The first part : (?=\b\w{9}\b) --> this makes sure the matched will be 9 characters long
    The second part : \w*\d\w* --> this is the main pattern, that is : at least one number, could be zero or more characters before and after this number

    Regards

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

    Re: Pattern for regex that matches one digit at least

    Now it is very clear for me. Thank you very very much
    Best and Kind 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