Regular expression to match email addresses

I am trying to check TextEdit to really contain an email address. I have a regex for this, but it checks for multiple addresses, and I just want to check only one address, no more.

Here you are an expression:

/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/

He checks for something like this:

yulien.paz@cav.desoft.cu, wcampbell@cav.desoft.cu

I need to take a second email address from TextEdit.

So how can I do this?

Note: I'm sorry, my English.

+3
source share
4 answers

Here is a large library of regular expressions

http://regexlib.com/Search.aspx?k=email

And a regular expression tester.

This is a sample http://regexlib.com/REDetails.aspx?regexp_id=88

^ ([\ -.] +) @(([([0-9] {1,3}) {3} [0-9] {1,3}.]) | (([\ W -.] +) +) ([A-Za-Z] {2,4})) $

+2
+1

To find an email address within a paragraph, none of the above work. Instead, you need to look for a word boundary, for example.

\b[_\S\d-]+@[_\S\d-]+\.[\S]{2,3}\b

Then use / g if necessary.

+1
source

try it

/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/
-3
source

Source: https://habr.com/ru/post/1733674/


All Articles