[Mimedefang] string compare / matching

Joseph Brennan brennan at columbia.edu
Fri Nov 30 12:16:07 EST 2007


Petra Humann <humann at tcs.inf.tu-dresden.de> wrote:


>     my $absender = $Sender;
>     $absender =~ s/^<//;
>     $absender =~ s/>$//;
>     $absender = lc($absender);
>
> If I write:
> 	if ( ! grep /$absender/, $from_header) ...
> it works, but some addresses doesn't, like "liste**recipient**@liste.com".



Beware of putting an email address into a regexp.  Perl will try to
interpret characters like * as quantifiers and complain.  Consider:


#!/usr/bin/perl
$thing  = 'liste**recipient**@liste.com';
$string = '**recip';
if ( grep /$string/, $thing) {
    print "matched\n";
}

$ perl -w test.pl
Quantifier follows nothing before HERE mark in regex ...


You can use \Q and \E to get around this:
    if ( grep /\Q$string\E/, $thing)


Joseph Brennan
Columbia University Information Technology




More information about the MIMEDefang mailing list