Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex pattern to match single dot

Tags:

regex

Is it possible to write a pattern such that it checks continuous occurrence of a character

should match

"[email protected]","[email protected]"

and it should not match

"[email protected]".

Basically i need this to check if the email address is valid

Any Suggestions?

like image 734
amponvizhi Avatar asked Aug 31 '25 10:08

amponvizhi


2 Answers

If the language supports it, you can use negative look-ahead and look-behind:

(?<!\.)\.(?!\.)

This will only match a period not following or preceding a period. See it in action here.

like image 64
Chris Seymour Avatar answered Sep 03 '25 05:09

Chris Seymour


You can invert you regex to match >1 dots - if it doesn't, string is valid:

\.{2,}
like image 41
hsz Avatar answered Sep 03 '25 05:09

hsz