regular expression to capture invalid emails

A

anonymous

Ok, what I want to do is simple. I want to create a regular expression that
matches any email address that ends in two characters like (e-mail address removed)
but not (e-mail address removed) my working regexp: (.*)@(.*)\.(\w){2}$
how do I change it so it doesn't match .us? I want to do it all in one
expression for specific reasons.
 
S

Sam Holden

Ok, what I want to do is simple. I want to create a regular expression that
matches any email address that ends in two characters like (e-mail address removed)
but not (e-mail address removed) my working regexp: (.*)@(.*)\.(\w){2}$
how do I change it so it doesn't match .us? I want to do it all in one
expression for specific reasons.

replace (\w){2} with (?!us)(\w){2}

assumming you want such strange capturing.

See "perldoc perlre" for details, and feel free to read it before
posting.
 
M

Matt Garrish

anonymous said:
Ok, what I want to do is simple. I want to create a regular expression that
matches any email address that ends in two characters like (e-mail address removed)
but not (e-mail address removed) my working regexp: (.*)@(.*)\.(\w){2}$
how do I change it so it doesn't match .us? I want to do it all in one
expression for specific reasons.

Assuming you're using a module like Email::Valid to check the validity of
the address first (no comments on all the ways your check above would fail),
you could just check that the address doesn't end with "us" or 3+
characters:

next if $email =~ /\.(us|\w{3,})$/i;

Matt
 
A

anonymous

Thanks, Sam I had a feeling that ?! was the answer but I didn't understand
its implementation. People like you are why Perl Rocks.
 
S

Sam Holden

Thanks, Sam I had a feeling that ?! was the answer but I didn't understand
its implementation. People like you are why Perl Rocks.

No people who write the code and submit patches and bug reports and
feedback and design and stuff deserve any credit for perl.

And top posting is frowned upon in these parts, see the posting
guidelines.
 
A

anonymous

You make good points Matt but I am only interested in filtering out emails
that end in two characters that are not us.
In what ways would the regexp fail to do that simple task?
 
G

gnari

[ please do not top post]
[rearranging the order of quoted lines]
You make good points Matt but I am only interested in filtering out emails
that end in two characters that are not us.
In what ways would the regexp fail to do that simple task?

Matt was talking about the email address validation. your regexp,
would for example accept the following addresses:
::::::mad:@@@@:::::mad:@@@.........tv
@.tv
I may be wrong, but these look invalid to me.

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top