ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Living Room

How to identify email address at the end of lines with RegEx?

<< < (3/4) > >>

wraith808:
That first regex that I put in works on that phrase just fine.  I didn't include the space in the regex because I thought that was just a miscommunication, after all, who'd want a space before the e-mail that they capture?

Ath:
That first regex that I put in works on that phrase just fine.
-wraith808 (June 07, 2020, 11:54 AM)
--- End quote ---
I fully agree, but as the OP has trouble reading (or understanding?) replies to his questions, I sort of tried to blow him off his socks, as all previous replies probably were too 'easy' :huh:

I didn't include the space in the regex
-wraith808 (June 07, 2020, 11:54 AM)
--- End quote ---
Well, there has to be some separator between any content and the e-mail address, and that's most likely a space.

wraith808:
Well, there has to be some separator between any content and the e-mail address, and that's most likely a space.
-Ath (June 07, 2020, 12:33 PM)
--- End quote ---

No, I mean that I didn't include it in the resulting match.  It would match like yours, just selecting the e-mail address.

4wd:
If would be helpful to know where this is going to be used, eg. in a spreadsheet, PowerShell, JavaScript, etc - there are system calls that could possibly do a better job of validating an email than a single RegEx although you still need to separate a suspected email address out of the input.

In PowerShell you could cast the assumed email address to the MailAddress type and let the system validate it, email addresses are no longer restricted to just ASCII characters.

eg. Valid email addresses:
johndoe@🚌.org
John.Doe@やる.net
[email protected]

Plain old ASCII valid email addresses:
John.Doe(Donationcoder)@nowhere.net
[email protected]
"John..Doe"@nowhere.net
"John. .Doe"@nowhere.net
"John@Doe"@nowhere.net

PS. The RegEx's given above fail the simplest email address: admin@localhost  ;)

Maybe you'd need to (roughly):

* look for a @ within the last 256 characters of the line, (max length of the domain part is 255);
* see if there are any pairs of quotes within the maximum allowed length of the local part, (64 chars), if there are you'd need to allow a lot more ASCII characters than you normally would, (eg. spaces, @);
* if there is an odd number of quotes then check that the 'odd' ones are escaped (\\);

* if there are no quotes in that 64 chars then take the chars at the first space backwards from the @;
* pass what you have to the system for validation.
Probably a lot more needs to be done in there before you can be sure you pick up anything that might be an email address.

wraith808:
PS. The RegEx's given above fail the simplest email address: admin@localhost 
-4wd (June 07, 2020, 11:03 PM)
--- End quote ---

Yeah, I assumed that he would have a tld, and didn't want to put too much into it as I was sure that it wouldn't be enough in any case.  :huh: :-[ :D :Thmbsup:

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version