CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Help with Regex matching scalar variable expression that may contain parentheses

 



douglazb
Novice

Dec 17, 2009, 7:17 AM

Post #1 of 2 (2573 views)
Help with Regex matching scalar variable expression that may contain parentheses Can't Post

I'm trying to capture the obituary details embedded inside a web page my matching the page contents with the page title. Many times the wife will list her maiden name inside parenthesis, causing my match to fail. Simple example:


Code
#!/usr/bin/perl -w 
use strict;
my $page_contents = "Please note that Mrs. Michelle E. (Brown) Smith passed away (along side her thirteen black cats) last Saturday. Continuing paragraphs, etc.";
my $page_title = "Mrs. Michelle E. (Brown) Smith";

if ($page_contents =~ /$page_title/)
{
print "Eek, bad luck!\n";
}else{
print "No match\n";
}

Escaping the parenthesis does not solve the problem:

Code
my $page_title = "Mrs. Michelle E. \(Brown\) Smith";


What aspect am I missing?

Thanks in advanced,

Douglas


shawnhcorey
Enthusiast


Dec 17, 2009, 8:48 AM

Post #2 of 2 (2565 views)
Re: [douglazb] Help with Regex matching scalar variable expression that may contain parentheses [In reply to] Can't Post

See:
perldoc -f quotemeta
perldoc perlre and search for /\\Q/

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives