Re: simple wildcard regex problem.



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

.



Relevant Pages

  • Re: Regexp: m and [^[:alnum:]_] are not equivalent
    ... Sanitizing an arbitrary user input for regexp is not simple at all. ... - Find a candidate string with the standard search capabilities of the ... >> an explicit set of characters before. ... > boundaries". ...
    (comp.lang.tcl)
  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
    (comp.programming)
  • RE: String manipulation question
    ... Subject: String manipulation question ... If the string is 34 characters or less, I'd like to append a colon ... perldoc -f length ...
    (perl.beginners)