Re: simple wildcard regex problem.
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 28 Apr 2006 07:14:06 -0700
Nikolas Britton wrote:
The short version is: How do I get $regex = qr{^...$}; to work.
It works just fine. You're looking for beginning of string, three
characters (not the newline), and end of string. What is the problem?
I get this error message, and I don't understand what it's telling me:
"Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE ]/ at
./temp.pl line 87, <DATA> line 2."
No you don't. There is no [ anywhere in the above code. You're not
giving us the code that generated that message.
------------------------------
Here's the long version: How do I get $regex = qr{^$regexstring$}; to
work.
No, the long ( and correct ) version would be one in which you show an
actual program, copied and pasted, so we can run.
while ($_ < "$numberofletters") {
Uhm. Ew. Please read:
perldoc -q quoting
$foo = substr($unsolvedword, $_, 1);
if ($foo eq "-"){
$regexstring .= ".";
} else {
$regexstring .= "$foo";
};
$_++;
This is almost never a good idea. There's just too many functions that
both assign to and read from $_. Use a real variable name.
}
As a pure guess, you're forgetting to escape whatever special regexp
characters might be inside your variable, and so they are being
interpolated in the regular expression, and then those special
characters (like, possibly, a ] or [ in your example above) are being
treated as part of the regexp.
You need to quote the special characters, using \Q...\E
my $regexp = qr{^\Q$foobar\E$};
perldoc -f quotemeta
Paul Lalli
.
- Follow-Ups:
- Re: simple wildcard regex problem.
- From: Nikolas Britton
- Re: simple wildcard regex problem.
- References:
- simple wildcard regex problem.
- From: Nikolas Britton
- simple wildcard regex problem.
- Prev by Date: Re: General Perl/Web questions
- Next by Date: Re: General Perl/Web questions
- Previous by thread: simple wildcard regex problem.
- Next by thread: Re: simple wildcard regex problem.
- Index(es):
Relevant Pages
|