develooper Front page | perl.beginners | Postings from April 2002

matching a [ in a regex

Thread Next
Timothy Johnson
April 2, 2002 10:06
matching a [ in a regex
Message ID:

When I try to do a pattern match on a variable that contains a '[', I get
the following error:

Unmatched [ before HERE mark in regex m/target[ << HERE / at
C:\PerlScripts\ line 5.

Here is my code so far:

$line = "my target[ target ]";

$t = "target[";
if($line =~ /$t/){
	print "yes";

I've tried escaping the bracket, etc, etc, to no avail.  Any suggestions?

Tim Johnson

This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About