amponvizhi
amponvizhi

Reputation: 51

regex pattern to match single dot

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?

Upvotes: 4

Views: 10491

Answers (4)

Lucas Hoepner
Lucas Hoepner

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

Chris Seymour
Chris Seymour

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

VladL
VladL

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

hsz
hsz

Reputation: 152216

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

\.{2,}

Upvotes: 2

Related Questions