I want to extract all valid email addresses from a given text.
Emails are considered to be in format user @ host, where:
• user is a sequence of letters and digits, where '.', '-' and '_' can appear between them.
• host is a sequence of at least two words, separated by dots '.'. Each word is sequence of letters and can have hyphens '-' between the letters, but ending with a letter.
• Examples of valid emails:
I wrote this regex:
/(?<!\S)[a-z0-9]+[\-\._]*[a-z0-9]+@[a-z]+\-*[a-z]+(\.[a-z0-9\-]+){1,}(?=\s|$)/g
But match and this case: [email protected]-
How to get rid of the last '-' ?