I have texts that can contain one email address or multiple ones. I use regex to match these. First I used: (from this previous question)
[A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)
This caused two problems. In the case a .
was used before the @
this was problematic, but also if an email address ended in two or more domain extensions (for example ...@domain.co.uk) it did not work. So I changed this expression to
^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})
This solves both first problems, but creates a new one. If in the text the email address is right before a full stop, this is now included in the address! So this text gives me problems:
Please email us at: some@example.com. You can also mail us at some@example.co.uk. Etc...
Is there a way to exclude this last .
if it is followed by either a blank space or a line break?
ps. I do not need to validate email addresses, I need to make sure my expression knows where an email address (or multiple) are in a text and when they stop.