How to find each lines that has upto 3 numbers in a list of email list
-
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.
-
@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 -
@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.
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?
-
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 thatthen5
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
-
@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. :) -
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
andWrap 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
andWrap 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
and3
digits only, which are all marked !Best Regards,
guy038
- E-mail addresses containing
-
@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.
-
@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
-
@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. :) -
@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.
-
@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.)
-
@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. :)
-
@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”?
-
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. :)
-
@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. -
@PeterJones Thank you sir, I will do that before posting here next time.