196
Living Room / Re: How to identify email address at the end of lines with RegEx?
« on: June 07, 2020, 10:47 AM »OK so what is the regex to capture the piece of text that starts with space and ends with the end of the line and can contain any character?That would look like this:-kalos (June 07, 2020, 08:22 AM)
.*\s+(\S+)$
What this does is:.* : Any character
\s+ : white-space, 1 or more consecutive
( : start group
\S+ : not white-space, 1 or more consecutive
) : end group
$ : end of line marker
You will have to get the group 1 value for your result, input like this:
a piece of text at the end of the line
will give you the word 'line' as a resultIf you are still searching for your original request, I took the first regex from https://emailregex.com, dropped it in the https://regex101.com regex tester, fixed the issues it reported (escape a few slashes because of the PCRE regex engine), and wrapped it with the construction I just showed here, and came up with this:
.*\s+((?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))$
If you feed that this text:test for email address with plain text prefix test@email.com
The only group that's there produces '[email protected]' as a result.Did I complete your assignment with this? ;)