I am searching the content of an email for a string using.
m/'Building: Walgreen Drug Store #\d+/ Does not find text.
But
index($t_subject, ‘Building: Walgreen Drug Store #’); Does find text.
A few (hopefully helpful) questions:
Why do have a single-quote character before the word Building in
the first example, but not in the second?
Can you send an example string that you searching over?
Better yet, can you send a snippet of your code?
And a note: if you are trying to capture text, you need parentheses
around the text you intend to capture. Something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $str=“And suddenly, there were Building: Walgreen Drug Store #235232343434324235521 flies in the tepid air”;
my ($substr) = ($str =~ m/(Building: Walgreen Drug Store #\d+)/);
print $substr, “\n”;
Also, you don’t mention whether this string occurs only in the email
headers, or also in the body? If in the body, will you have to deal
with the possibility of a line break occuring inside the string?
The single quote must have been a typo In the email. I switch the code to use regex for the search see results below. Using index still works just need to change brain thought to get it to work similar to regex. I still think the issue is the double quotes in the content text.
I have done some other test using the Padre ide if I take out the double quotes the regex search works.
Here is the codes being used.
my $t_subject = $self->TransactionObj->ContentObj->Content ;
my $match = “Building: Walgreen Drug Store”;
if ( $t_subject !~ /$match/i) {
$RT::Logger->debug(“Found Match\n”);
return 0;
}
else {
$RT::Logger->debug(“No Match Found Match string: $match content: $t_subject\n”);
return 1;
}
Here is the log entry when the search fails and the content is in the log as well.
Thanks for the help
[Fri Aug 9 16:08:02 2013] [debug]: No Match Found Match string: Building: Walgreen Drug Store content:
The Walgreens Facilities Maintenance Svc Ctr has assigned a work order for service to Copesan Services Inc.
The referenced work order number is C2239243
Below are the details:
Date Entered: Jul 18 2013 9:22AM CST
Priority: P5 - Medium (5 Business Day Response)
Target Response: Jul 25 2013 9:22AM CST
Target Completion: Jul 25 2013 9:22AM CST
Service Location:
5600 W Fullerton, Chicago, IL, 60639-2305, US
Cntry, St, City: US, IL, Chicago-North Mkt
Building: Walgreen Drug Store #4233
Floor: All: 5600 W Fullerton
Area: Walgreen Drug Store #4233
Location within Area: (Not provided by Requestor)
Requestor Name: LAURA DWORAKOWSKI
Requestor Phone: 773-745-1640
Contact Name: LAURA DWORAKOWSKI
Contact Phone: (773) 637-4440
Problem Description: PEST CONTROL - NON EMERGENCY Insect/Rodent/Termite/Animal:>FLIES ARE EVERYWHERE IN THE STORE.
Order Status: O - Open
Cost of work should not exceed 300.00 USD. If the cost of completing the work will exceed this amount please contact the Walgreens Facilities Maintenance Svc Ctr for approval/authorization before proceeding with the work.
If you have any questions about this work order, please contact the Walgreens Facilities Maintenance Svc Ctr at 877-871-3128
Notes to Vendor:
To help ensure timely payment, please use the Vendor Activity Website to complete the order, providing arrival, departure and a description of work performed. Please use the Vendor Activity Website to submit detailed invoice information for billable services.
Vendor shall adhere to all current safety regulations and standard company guidelines.
Vendor shall be licensed, insured and bonded as required by regional/local laws where the work is being performed.
In accordance with the financial terms of the FACILITIES MANAGEMENT OUTSOURCING SERVICES AGREEMENT by and between WALGREEN CO. and CBRE, Effective as of May 13, 2011, CBRE will be paying third party vendors according to Net 35 terms. This is effective upon the assumption of existing or creation of new vendor relationships between CBRE and third party providers of goods and/or services to CBRE or WALGREENS on behalf of CBRE." ((eval 1542):8)
[Fri Aug 9 16:08:02 2013] [debug]: Committing scrip #15 on txn #1022 of ticket #96 (/usr/lib/perl5/vendor_perl/5.16.2/RT/Scrips.pm:182)
[Fri Aug 9 16:08:02 2013] [error]: Scrip 15 Commit failed: RT::Body Unimplemented in RT::Action::UserDefined. ((eval 1549) line 12)
Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726 • 262-783-6261 ext. 2296 bbaker@copesan.com
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.
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@copesan.com
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.
Ok moving on
So the “Custom action preparation code” is working
I added this to the “Custom action cleanup code:”
use strict;
use warnings;
Start Area for Request Tracker
my $storenumber = “4223”;
my $wonumber = “C2239243”;
$RT::Logger->debug(“Clean up Found Work Order: $wonumber Store: $storenumber\n”);
return 1;
and all I get in the log is
[Fri Aug 9 18:13:49 2013] [debug]: Found match for Walgreens, C2239243, 4233 ((eval 1635):8) (From the “Custom action preparation code”)
[Fri Aug 9 18:13:49 2013] [debug]: Skipping Scrip #15 because it didn’t Prepare (/usr/lib/perl5/vendor_perl/5.16.2/RT/Scrips.pm:237)
Where is the message from the “Custom action cleanup code:”?
Thanks
Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726 • 262-783-6261 ext. 2296 bbaker@copesan.com
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.
Again thanks Nathan for the help on the regex stuff.
Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726 • 262-783-6261 ext. 2296 bbaker@copesan.com
"Servicing North America with Local Care"From: Bryon Baker
Sent: Friday, August 09, 2013 1:19 PM
To: ‘Nathan Cutler’; rt-users@lists.bestpractical.com
Subject: RE: [rt-users] Searching for a string
Ok moving on
So the “Custom action preparation code” is working I added this to the “Custom action cleanup code:”
use strict;
use warnings;
Start Area for Request Tracker
my $storenumber = “4223”;
my $wonumber = “C2239243”;
$RT::Logger->debug(“Clean up Found Work Order: $wonumber Store: $storenumber\n”);
return 1;
and all I get in the log is
[Fri Aug 9 18:13:49 2013] [debug]: Found match for Walgreens, C2239243, 4233 ((eval 1635):8) (From the “Custom action preparation code”)
[Fri Aug 9 18:13:49 2013] [debug]: Skipping Scrip #15 because it didn’t Prepare (/usr/lib/perl5/vendor_perl/5.16.2/RT/Scrips.pm:237)
Where is the message from the “Custom action cleanup code:”?
Thanks
Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726 • 262-783-6261 ext. 2296 bbaker@copesan.com
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.