RegEx Problem
- From: Jerry Baker <jerry@xxxxxxxxxxxxxxxx>
- Date: Wed, 21 Jun 2006 16:31:52 GMT
Special characters inside of variables cannot be escaped, but Perl tries to use them in a RegEx. Try this example program to see what I mean:
-----PROGRAM-----
#!/usr/bin/perl
$test = "This + test";
$test2 = "+";
if($test =~ /^This $test2 test$/) {
print "WORKS!!!";
}
else {
print "DOESN'T WORK";
}
-----PROGRAM-----
The result will always be "DOESN"T WORK". The same result will occur if you change $test2 = "\+".
To verify that the program isn't at fault, the following always returns "WORKS!!!":
-----PROGRAM-----
#!/usr/bin/perl
$test = "This + test";
if($test =~ /^This \+ test$/) {
print "WORKS!!!";
}
else {
print "DOESN'T WORK";
}
-----PROGRAM-----
How can I tell Perl to ignore "special" characters in a variable when performing a RegExp comparison?
Thanks.
.
- Follow-Ups:
- Re: RegEx Problem
- From: Jerry Baker
- Re: RegEx Problem
- Prev by Date: Re: hash of arrays question
- Next by Date: Re: RegEx Problem
- Previous by thread: hash of arrays question
- Next by thread: Re: RegEx Problem
- Index(es):
Relevant Pages
|
|