I want to detect emails in text format so that I can put an anchor tag over them with mailto tag in anchor. I have the regex for it but the code also detects emails which are already encapsulated by anchor tag or is inside the anchor tag mailto parameter.
My regex is:
([\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?)
But it detects 3 matches in the following sample text:
ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc email@email.com
I want only email@email.com to be matched by the regex.
Very similar to my previous answer to your other question, try this
The only thing that is really different is the word boundary
\bbefore the start of the email.See a similar expression here on Regexr, its not exactly the same, because Regexr does not support alternations and infinite length in the lookbehind.