[rt-users] Searching for a string
Bryon Baker
bbaker at copesan.com
Fri Aug 9 13:37:02 EDT 2013
Here is the code I am using now:
my $t_subject = $self->TransactionObj->ContentObj->Content ;
if ($t_subject =~ /Building:\s+Walgreen Drug Store/is)
{
$RT::Logger->debug("Found Match\n");
return 0;
}
else
{
$RT::Logger->debug("No Match Found Match content: $t_subject\n");
return 1;
}
This is working thanks Nathan :)
Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726 • 262-783-6261 ext. 2296
bbaker at copesan.com
www.copesan.com
"Servicing North America with Local Care"
-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Nathan Cutler
Sent: Friday, August 09, 2013 11:59 AM
To: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Searching for a string
Hi Bryon:
Perl regexes can be a bit tricky.
> Here is the codes being used.
>
> my $t_subject = $self->TransactionObj->ContentObj->Content ; my $match
> = "Building: Walgreen Drug Store";
Here I would be to use \s+ after the colon, since there might be multiple spaces or even a tab in the email. Unless you're sure it will always be just a single space.
> if ( $t_subject !~ /$match/i) {
This says "if $t_subject does NOT match". Don't you want the opposite?
I'd suggest you try changing the !~ operator (does NOT match) in this line to =~ (matches).
> $RT::Logger->debug("Found Match\n");
> return 0;
> }
> else {
> $RT::Logger->debug("No Match Found Match string: $match content: $t_subject\n");
> return 1;
> }
Another thing to try is the "s" modifier, which explicitly tells Perl to treat the entire email as a single line. But in my test it works fine without.
Hope this helps.
Nathan
More information about the rt-users
mailing list