• Login
Community
  • Login

How to find each lines that has upto 3 numbers in a list of email list

Scheduled Pinned Locked Moved General Discussion
17 Posts 6 Posters 1.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    Mendella Replacement
    last edited by PeterJones Jan 13, 2023, 5:57 PM Jan 13, 2023, 4:21 PM

    Greetings everyone,
    Please I have a task I wish to accomplish.
    I have a list of email addresses of my customers that are mixed with alphabets and numbers together.
    Now, I want to be able to figure out any line in the document that has up-to 3 numbers in each email addresses and able to mark them out. That is checking from beginning to the end of each line and be able to determine how many numbers in the email.
    I used this option \d{3} with reg. but what it does is different from what I want to do. This “\d{3}” is only able to determine each lines that has 3 numbers together.
    for instances, herbert200@nelkerson23.com, keneth33faith244@gmail.com.
    But what I need is to be able to sort out any email list that has upto 3 numbers in it, whether its together written or not. Something like this, e.g magret28@doirana1.com, bethel02chruchhill4@gmail.com.
    You can see clearly that the last two examples has only 3 numbers in each email addresses. I need an argument that can be able to pick them out please.
    Thank you for your positive response and contribution in advances.
    God bless you all.

    –
    moderator added plaintext markers around the email addresses so that people aren’t clicking the mailto: links that get created

    M M 2 Replies Last reply Jan 13, 2023, 5:08 PM Reply Quote 0
    • M
      Michael Vincent @Mendella Replacement
      last edited by Jan 13, 2023, 5:08 PM

      @Mendella-Replacement

      https://chat.openai.com/

      Michael Vincent:
      Do you understand regular expressions?

      ChatGPT:
      Yes, I am familiar with regular expressions and can assist with tasks such as pattern matching, text manipulation, and data extraction. Is there a specific question or task you would like me to help with?

      Michael Vincent:
      Can you show me a regular expression that checks if there are at least three numbers in an email address?

      ChatGPT:
      Sure, here is a regular expression that checks if there are at least three numbers in an email address:

      (?=.*[0-9])[0-9]{3,}

      This regular expression uses a positive lookahead (?=.*[0-9]) to ensure that at least one number is present in the email address, and then matches three or more numbers [0-9]{3,}.

      You can test it using for example python re module

      import re
      
      pattern = "(?=.*[0-9])[0-9]{3,}"
      email_addresses = ["test123@example.com", "test@example.com", "test12@3example.com"]
      
      for email in email_addresses:
          if re.search(pattern, email):
              print(f"{email} has at least 3 numbers")
          else:
              print(f"{email} has less than 3 numbers")
      

      It will output:

      test123@example.com has at least 3 numbers
      test@example.com has less than 3 numbers
      test12@3example.com has at least 3 numbers
      

      Cheers.

      A P 2 Replies Last reply Jan 13, 2023, 6:10 PM Reply Quote 2
      • A
        Alan Kilborn @Michael Vincent
        last edited by Alan Kilborn Jan 13, 2023, 6:18 PM Jan 13, 2023, 6:10 PM

        @Michael-Vincent said in How to find each lines that has upto 3 numbers in a list of email list:

        Michael Vincent:
        Can you show me a regular expression that checks if there are at least three numbers in an email address?

        Michael Vincent failure in the problem statement: OP wants “up to 3”, not “at least 3”.

        If the AI was smarter it would have coughed up:
        https://community.notepad-plus-plus.org/topic/20410 Dec 2, 2020, 2:35 PM

        L M 2 Replies Last reply Jan 13, 2023, 6:22 PM Reply Quote 2
        • L
          Lycan Thrope @Alan Kilborn
          last edited by Lycan Thrope Jan 13, 2023, 6:28 PM Jan 13, 2023, 6:22 PM

          @Alan-Kilborn
          I thought his response was funny though, showing the error of AI. :)

          Here’s a screenshot of Mark showing the mistake on just a random list of characters plus the test cases asked by the OP.

          numbercounterror.PNG

          Of course, I may now feel compelled to find the right answer. :( Which I’d rather see the OP try, since they haven’t even read the FAQ’s yet to post the question with proper trial and error. On the other hand, this looks more like a programming problem rather than just a s/r question, doesn’t it?

          M 1 Reply Last reply Jan 13, 2023, 6:56 PM Reply Quote 1
          • P
            PeterJones @Michael Vincent
            last edited by PeterJones Jan 13, 2023, 6:38 PM Jan 13, 2023, 6:35 PM

            Unfortunately, there are actually a lot of edge cases, that would make the Dec 2020 solution probably not work (because a1b2@example.com then5 might match as a whole if the .* portion of the solution from 2020 were used, because even though the space means that then5 isn’t part of the email, it would still match that pattern).

            There is also a lack of clarity in the OP’s requirements:

            herbert200@nelkerson23.com
            keneth33faith244@gmail.com
            magret28@doirana1.com
            bethel02chruchhill4@gmail.com
            

            Based on original problem statement, I am not sure whether the first and second should match or not: they seemed to be used by the OP as an example of something that did match, but I’m not sure if they should match, since they violate the “up to 3” since they each have a total of 5 digits.

            I came up with a possible solution (with caveats). If the OP is really a person, and not an AI that is using our forum as a training ground, they should be able to find the right menu entry in Notepad++ to decode this base64 answer

            RklORCA9IGAoPzpefCx8XHN8InwnKVxLKD89XFMrQFxTKykoW15cZFxzXSpcZCl7MSwzfVteXGRcc10rKD89JHwsfFxzfCJ8JylgDQoNCkkgYWRkZWQgcmVzdHJpY3Rpb25zIHRoYXQgYmVmb3JlIGFuIGVtYWlsIGhhZCB0byBiZSBlaXRoZXIgYSBzdGFydC1vZi1saW5lIG9yIGEgY29tbWEgb3Igd2hpdGVzcGFjZSBvciBzaW5nbGUvZG91YmxlIHF1b3RlIG1hcmssIGFuZCBhZnRlciB0aGUgZW1haWwgaGFkIHRvIGJlIGVpdGhlciBFT0wgb3IgY29tbWEgb3Igd2hpdGVzcGFjZSBvciBzaW5nbGUvZG91YmxlIHF1b3RlIG1hcmsgb3IgRU9GLiAgWW91IG1pZ2h0IGhhdmUgb3RoZXIgYWxsb3dlZCBjaGFyYWN0ZXJzIHRoYXQgeW91IGNhbiBhZGQgdG8gdGhvc2UgKG1heWJlIGFsbG93aW5nIGA8ZW1haWwxMjNAZXhhbXBsZS5jb20+YCBvciBgPG1haWx0bzplbWFpbDEyM0BleGFtcGxlLmNvbT5gIHRocm91Z2ggYSBwcmVmaXggb2YgYDxgIG9yIGA6YCBhbmQgYSBzdWZmaXggb2YgYD5gIGFkZGVkIHRvIHRoZSBhbHRlcm5hdGlvbiBsaXN0KQ0K
            

            ----

            Useful References

            • Please Read Before Posting
            • Template for Search/Replace Questions
            • Formatting Forum Posts
            • Notepad++ Online User Manual: Searching/Regex
            • FAQ: Where to find other regular expressions (regex) documentation
            L M 3 Replies Last reply Jan 13, 2023, 6:45 PM Reply Quote 1
            • L
              Lycan Thrope @PeterJones
              last edited by Jan 13, 2023, 6:45 PM

              @PeterJones ,
              Unfortunately, I’ve never played with base64.:( So I guess I’ll have to find this magical mythical tool of which you speak. :) I have my own somewhat solution, but until I find out if it matches yours, I’ll hold still. :)

              1 Reply Last reply Reply Quote 0
              • G
                guy038
                last edited by guy038 Jan 13, 2023, 7:49 PM Jan 13, 2023, 6:45 PM

                Hello, @mendella-replacement, @michael-vincent, @alan-kilborn, @lycan-thrope, @peterjones and All,

                @mendella-replacement, as you said :

                … to figure out any line in the document that has up-to 3 numbers in each email addresses …

                I assume that you would like to mark :

                • E-mail addresses containing 3 digits ONLY

                OR

                • E-mail addresses containing 2 digits ONLY

                OR

                • E-mail addresses containing 1 digit ONLY

                OR

                • E-mail addresses containing 0 digit

                If so, and given this INPUT text :

                abcd@gmail.com
                herbert200@nelkerson23.com
                magret28@doirana1.com
                bethel0chruchhill24@gmail.com
                abc1def2ghi3@gmail.com
                123_no_good_adr_456789@toto.com
                test12@hotmail.com
                guy.123@mysite.com
                keneth3faith244@gmail.com
                adr_0_till_9.@gmail.com
                guy0thevenot@gmail.com
                

                Follow this road map :

                • Open the Mark dialog ( Ctrl+ M )

                • SEARCH (?x) ^ [^\d\r\n]* (?: \d [^\d\r\n]* \d [^\d\r\n]* \d | \d [^\d\r\n]* \d | \d ) [^\d\r\n]* $ | ^ [^\d\r\n]+ $

                • Untick all the box options

                • Tick the Purge for each search and Wrap around options

                • Select the Regular expression search mode

                • Click on the Mark All button

                • Click on the Copy Marked Text button

                • Close the Mark dialog ( Esc )

                • Open a new tab ( Ctrl + N )

                • Paste the copied lines ( Ctrl + V ) in this new tab

                => You should get this expected OUTPUT text, which contain not more than 3 digits per line :

                abcd@gmail.com
                magret28@doirana1.com
                bethel0chruchhill24@gmail.com
                abc1def2ghi3@gmail.com
                test12@hotmail.com
                guy.123@mysite.com
                adr_0_till_9.@gmail.com
                guy0thevenot@gmail.com
                

                In order to visualize all these concerned digits of this new tab :

                • Open again the Mark dialog ( Ctrl + M )

                • SEARCH \d+

                • Untick all the box options

                • Tick the Purge for each search and Wrap around options

                • Select the Regular expression search mode

                • Click on the Mark All button

                As you can see, any e-mail address, in this new tab, contains between 0 and 3 digits only, which are all marked !

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 2
                • M
                  Michael Vincent @Lycan Thrope
                  last edited by Jan 13, 2023, 6:56 PM

                  @Lycan-Thrope said in How to find each lines that has upto 3 numbers in a list of email list:

                  Which I’d rather see the OP try

                  That was entirely my point of posting the ChatGPT interaction. There are plenty of resources online - and they’re getting even easier to use - that one can test and show their work before coming here and asking for a solution.

                  Cheers.

                  L 1 Reply Last reply Jan 13, 2023, 6:59 PM Reply Quote 2
                  • L
                    Lycan Thrope @PeterJones
                    last edited by Jan 13, 2023, 6:58 PM

                    @PeterJones ,
                    Well, I learned something new. I guess I can start using NPP to see what all those base64 things are. :)

                    Anyway, your solution seemed to be erred, but I’m not sure if mine is completely fulfilling the desired result, as all it does is highlight the numbers, and leaves the counting to the OP. :)

                    In my newly learned trick of NPP, I guess my answer shall go here the same way yours does. :)

                    XGR7MX0r
                    
                    P 1 Reply Last reply Jan 13, 2023, 7:22 PM Reply Quote 0
                    • L
                      Lycan Thrope @Michael Vincent
                      last edited by Jan 13, 2023, 6:59 PM

                      @Michael-Vincent
                      As you can tell, typed sarcasm, although I obviously got your point, isn’t my strong suit. :) LOL However, your point was not lost on my lack of ability to sense sarcasm in the typed word. :)

                      1 Reply Last reply Reply Quote 0
                      • M
                        Michael Vincent @Alan Kilborn
                        last edited by Jan 13, 2023, 7:00 PM

                        @Alan-Kilborn said in How to find each lines that has upto 3 numbers in a list of email list:

                        Michael Vincent failure in the problem statement: OP wants “up to 3”, not “at least 3”.

                        Yeah, my bad, I didn’t read the exact question into ChatGPT. The point being though that the OP could have done so and showed some work / effort before asking for solution. I sometimes feel like this forum has become a regex writing service when plenty exist online and if one is too “scared” or “confused” where to start - simply speak your requirement into ChatGPT and get something to start with. It’s really never been simpler to show some effort by our posters (not directed the forum “regulars” who answer these questions again and again … and again …).

                        Cheers.

                        1 Reply Last reply Reply Quote 3
                        • P
                          PeterJones @Lycan Thrope
                          last edited by PeterJones Jan 13, 2023, 7:25 PM Jan 13, 2023, 7:22 PM

                          @Lycan-Thrope said in How to find each lines that has upto 3 numbers in a list of email list:

                          In my newly learned trick of NPP, I guess my answer shall go here the same way yours does. :)
                          XGR7MX0r

                          That solution requires the digits to be in a row. And will allow for any number of digits, not limiting it to “up to 3”. (See what happens when you use that against the text 1234567890, and see how much of that text it gobbles in a single match). Also, it will only match the digits, not the entire email address.

                          (Actually, re-reading the OP, it might require that the email is alone on the line, with 0-3 numbers. It’s hard to tell, because the OP didn’t put enough detail in the problem statement, and has never come back to clarify. Until they do, I will stop thinking about this problem.)

                          L 1 Reply Last reply Jan 13, 2023, 7:30 PM Reply Quote 1
                          • L
                            Lycan Thrope @PeterJones
                            last edited by Lycan Thrope Jan 13, 2023, 7:31 PM Jan 13, 2023, 7:30 PM

                            @PeterJones Yes, I noticed after playing a little more, it gets all numbers, but then again, the OP didn’t specify that it only show the ones with up to 3, only that it wants to determine for them to mark that it has up to 3… my solution was just to show only the numbers and let them count them, but they are marked that they have numbers. :)

                            I have to add though, it is something I’m going to play around with, as this will give me something to use should the issue arise. :)

                            P 1 Reply Last reply Jan 13, 2023, 7:41 PM Reply Quote 0
                            • P
                              PeterJones @Lycan Thrope
                              last edited by Jan 13, 2023, 7:41 PM

                              @Lycan-Thrope said in How to find each lines that has upto 3 numbers in a list of email list:

                              OP didn’t specify that it only show the ones with up to 3

                              Um, the title literally says, “How to find each lines that has upto 3 numbers in a list of email”. How is that not asking for “up to 3”?

                              L 1 Reply Last reply Jan 13, 2023, 7:57 PM Reply Quote 1
                              • L
                                Lycan Thrope @PeterJones
                                last edited by Lycan Thrope Jan 13, 2023, 11:28 PM Jan 13, 2023, 7:57 PM

                                @PeterJones ,

                                Later in the description:

                                Now, I want to be able to figure out any line in the document that has up-to 3 numbers in each email addresses and able to mark them out. That is checking from beginning to the end of each line and be able to determine how many numbers in the email.

                                According to their test, they used \d{3} but it only showed 3 numbers together. Mine shows them all, so they can make that determination of whether to mark it or not. Semantics at work again. :) But according to the test they show and the wording of their request after the title statement, this solution seems to follow what they later explain they meant.

                                Edit: I have got to figure out this markdown to figure out how to put quotes in where I want them. So I used code for this quote…sorry. @Alan-Kilborn showed me how…now where is that manual. :) Found references from the FAQ and then followed links. Will be better formatter now. :)

                                1 Reply Last reply Reply Quote 0
                                • M
                                  Mendella Replacement @Mendella Replacement
                                  last edited by Jan 14, 2023, 5:58 AM

                                  @Mendella-Replacement Thank you so much. I’m sorry, I seem to have failed a lot of rules here. I’m new here, not really a coder, lol.
                                  I was only trying to fix this error for my manager in the office.
                                  I have read your suggestions, I will try them out and report back.

                                  1 Reply Last reply Reply Quote 0
                                  • M
                                    Mendella Replacement @PeterJones
                                    last edited by Jan 14, 2023, 6:02 AM

                                    @PeterJones Thank you sir, I will do that before posting here next time.

                                    1 Reply Last reply Reply Quote 0
                                    5 out of 17
                                    • First post
                                      5/17
                                      Last post
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors