Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex if all words contains particular symbols [duplicate]

Tags:

c#

.net

regex

I have a string of emails "[email protected]; [email protected]; [email protected]"

how to write simple regex to check if all words contains [@.] at least once in the word?

like image 951
Reno Avatar asked Oct 04 '22 22:10

Reno


1 Answers

No need for regex:

bool allOk = str.Split(';').All(email => email.Count(c => c == '@') == 1);

Although this may lead to erronous results (foo@bar_foo.com is not a valid email!)

like image 175
Ahmed KRAIEM Avatar answered Oct 07 '22 20:10

Ahmed KRAIEM