Reputation: 51
Is it possible to write a pattern such that it checks continuous occurrence of a character
should match
and it should not match
Basically i need this to check if the email address is valid
Any Suggestions?
Upvotes: 4
Views: 10491
Reputation: 1447
There are regex for email validation. No need to reinvent the wheel.
What would work with your examples should be (\w\.?)+@(\w\.?)+
Upvotes: 1
Reputation: 85785
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.
Upvotes: 7
Reputation: 13033
This will match one dot in a row in every string
\.[^.]
or you can check for all characters which should be there only one time in a row
[.-,]{1}
Upvotes: 0
Reputation: 152216
You can invert you regex to match >1
dots - if it doesn't, string is valid:
\.{2,}
Upvotes: 2