I want to select only email id within angular brackets without affecting other regex part

Viewed 17

I created a regex for selecting valid email id & url which ignore special characters at start and had a strict rule for selecting email id & urls.

here is my regex: https://regex101.com/r/DMKCdF/1

(?:^|\s)((ftp|https?):\/\/|(www\.)|(mailto:)?[^$.@#%\^()_=+*&][A-Za-z0-9]*[._-]?([A-Za-z0-9])*@)\.?[A-Za-z0-9_%+-]+(\.[\w]+[a-zA-Z0-9\/]*?)+(?!\S)

Currently, i'm able to select email with space before and after it. Please refer below image:

enter image description here

i want to modify above regex, where i can select only email id excluding brackets.

Expected result:

enter image description here

I want to select email as mention in expected result excluding brackets.

Please modify regex mention in the link or suggest me work around so i can achieve expected result.

Thanks

1 Answers

Not sure, if I get your question right (and I cannot comment), but you could use a regex like this to match email addresses:

[A-Za-z0-9](([a-zA-Z0-9,=\.!\-#|\$%\^&\*\+/\?_`\{\}~]+)*)@(?:[0-9a-zA-Z-]+\.)+[a-zA-Z]{2,9}

Maybe it would be helpful if you could add positive/negative examples that should (not) match.

Related