Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unmatched ()

Status
Not open for further replies.

Graziella

Programmer
Jul 8, 2004
38
AT

Hello,
with these lines of code
if ($buf =~ /($pattern)/){
$match = $1;
print "MATCH $match\n";
}

I get the error message "unmatched () in regexp ...". No surprise since $pattern is actually a regex, and might contain unmatched ( and similar.
For this reason, if I use \Q, I will no longer have a regex in $pattern, because all \ ? * etc. will be commmented out.
What other option do I have to avoid the error and still be able to match it with $1 in the second line above ?

Thank you,

Grazia
 
If $pattern is a regex, then Perl is correct in rejecting it due to invalid syntax. If you want a regex to treat any special characters literally, then those characters need to be escaped, for example ( to \( .
 
You could try using the quotemeta function on $pattern - it might do what you're looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top