[rt-users] Searching for a string

Nathan Cutler presnypreklad at gmail.com
Fri Aug 9 12:58:52 EDT 2013


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