in reply to Re: Regex Expression to filter email for Barracuda Email Appliance
in thread Regex Expression to filter email for Barracuda Email Appliance
I think this is the right answer. Pay for the service or software that experts in this problem domain provide for solving the problem. The OP's heuristics will eventually fall short of being adequate, or will generate false positives in some esoteric cases that don't matter until something important gets rejected. There are people for whom email safety is a core competency. For the rest of us, there are better problems to spend time solving.
On the other hand, if a regex solution really is needed, I'd still break it into two; one that triggers if the person's name is detected, and another that validates there is a proper email address, or that flags if there is not.
If it has to be done from a single regex, you could do a negative lookahead, but it just gets more complicated. Here's a working example with a negative lookahead. But I consider it fragile:
#!/usr/bin/env perl use strict; use warnings; use feature qw(say); my @strings = ( 'From: John Doe <peter@piper.com>', 'From: John Doe <john@doe.com>', 'From: John Doe', ); foreach my $string (@strings) { if ($string =~ m/^From:\s+John\s+Doe(?!\s+<john\@doe\.com>)/) { say "BAD: $string" } else { say "GOOD: $string" } }
Dave
|
---|