Regular expression, excluding .. in suffix of email addy

Posted by user1754700 on Stack Overflow See other posts from Stack Overflow or by user1754700
Published on 2012-10-17T22:51:45Z Indexed on 2012/10/17 23:00 UTC
Read the original article Hit count: 218

Filed under:

This is homework, I've been working on it for a while, I've done lots of reading and feel I have gotten pretty familiar with regex for a beginner.

I am trying to find a regular expression for validating/invalidating a list of emails. There are two addresses which are giving me problems, I can't get them both to validate the correct way at the same time. I've gone through a dozen different expressions that work for all the other emails on the list but I can't get those two at the same time.

First, the addresses.

[email protected]  - invalid
[email protected]  - valid

The part of my expression which validates the suffix

I originally started with

@.+\\.[[a-z]0-9]+

And had a second pattern for checking some more invalid addresses and checked the email against both patterns, one checked for validity the other invalidity but my professor said he wanted it all in on expression.

@[[\\w]+\\.[\\w]+]+

or

@[\\w]+\\.[\\w]+

I've tried it written many, many different ways but I'm pretty sure I was just using different syntax to express these two expressions.

I know what I want it to do, I want it to match a character class of "character+"."character+"+

The plus sign being at least one. It works for the invalid class when I only allow the character class to repeat one time(and obviously the ip doesn't get matched), but when I allow the character class to repeat itself it matches the second period even thought it isn't preceded by a character. I don't understand why.

© Stack Overflow or respective owner

Related posts about regex