
douglazb
Novice
Dec 17, 2009, 7:17 AM
Post #1 of 2
(1689 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:
#!/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:
my $page_title = "Mrs. Michelle E. \(Brown\) Smith"; What aspect am I missing? Thanks in advanced, Douglas
|