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?

<< < (2/4) > >>

kalos:
I don't understand, the below matches " text1 text2 [email protected]".

Why does it includes spaces in between since it is enclosed in \b?


--- --- \b(.+?\.com)\b

Ath:
Why are you trying to use something you don't know how to construct (you are not even checking for the mandatory @ and .  >:(), if there are several working examples and links in posts above yours? Please use the advice that's given, for free, by ppl that actually know what they are talking about.

mouser:
You might also check out my program, Regex Captor:
https://www.donationcoder.com/forum/index.php?topic=45497

kalos:
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?

Ath:
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?

-kalos (June 07, 2020, 08:22 AM)
--- End quote ---
That would look like this:

--- ---.*\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 linewill give you the word 'line' as a result

If 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? ;)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version