P
P
Pavel Ivanov2016-03-11 15:10:22
Python
Pavel Ivanov, 2016-03-11 15:10:22

How to exclude two dots from an email address using regexp?

There is a task:


Write a function that checks the e-mail entered by the user for compliance with the following rules:
1. e-mail consists of a name and a domain part, these parts are separated by the "@" character;
2. the domain part is not shorter than 3 characters and not longer than 256, is a set of non-empty strings consisting of the characters az 0-9_- and separated by a dot;
3. each component of the domain part cannot begin or end with the "-" character;
4. name (before @) no longer than 128 characters, consists of characters a-z0-9"._-;
5. two periods in a row are not allowed in the name;
6. if the name contains double quotes ", then they must be paired ;
7. characters "!,:" can occur in the name, but only between paired double quotes.

There is a regular expression that I wrote:
((?!-)[A-Z0-9"\.\-_]{1,128}(?<!-)@(?!-)[A-Z0-9\-_.]{3,256}(?<!-))

Reached the 5th point, then plugging. I'm trying to use
|(?:\.(?!\.))
at the end to exclude dots - it doesn't work and doesn't check the string.
How to wedge an exception into my solution so that it works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2016-03-11
@dimonchik2013

Do you know the parable about the Columbus egg ?
Why are you cramming everything into one statement? you need a function, and not just one single regexp
, this is obvious from 6-7 points, which cannot be solved in one regexp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question