Lola1234
Lola1234

Reputation: 13

Email Extractor Java Pattern excluding characters before a dot

I am currently using an email extractor which is working well, but I would like to change its pattern which is:

[^a-zA-Z0-9-](?<num>[a-zA-Z0-9_-]{2,20}@[A-Za-z0-9_-]{3,20}\.[\.a-zA-Z0-9_-]+)[^a-zA-Z0-9_-]

The problem with this pattern is that it excludes all the charaters before a dot.

For example, if it finds an email like "[email protected]", it will report "[email protected]"

I don't know what I should write in the pattern so it does not exclude the characters before the dot anymore.

If someone has an idea, please let me know... many thanks!!

Upvotes: 1

Views: 160

Answers (1)

anubhava
anubhava

Reputation: 784898

Your regex doesn't seem right, try this regex:

\b(?<num>[a-zA-Z0-9][\w.-]{2,20}@[\w-]{3,20}\.[.\w-]+)\b

RegEx Demo

Upvotes: 1

Related Questions