develooper Front page | perl.perl5.porters | Postings from October 2014

Re: Expected behavior of \Q inside a bracketed character class?

Thread Previous | Thread Next
From:
Eric Brine
Date:
October 15, 2014 19:18
Subject:
Re: Expected behavior of \Q inside a bracketed character class?
Message ID:
CALJW-qGJ+8nn-ASK4MEr2680Bi8RE7rYt=QVMPmKRwH7Xncg3w@mail.gmail.com
On Wed, Oct 15, 2014 at 2:22 AM, Eirik Berg Hanssen <
Eirik-Berg.Hanssen@allverden.no> wrote:

>   ... and yes, this seems to contradict the documentation's "not
> usable within a bracketed character class".
>

"Seem" is right.

The documentation is correct. \Q is not recognized in character classes.

$ perl -we'$_ = q{[\Qa-z]}; qr/$_/'
Unrecognized escape \Q in character class passed through in regex; marked
by <-- HERE in m/[\Q <-- HERE a-z]/ at -e line 1.

In fact, \Q is not recognized in regex, period.

$ perl -we'$_ = q{\Q.}; qr/$_/'
Unrecognized escape \Q passed through in regex; marked by <-- HERE in m/\Q
<-- HERE ./ at -e line 1.

\Q..\E are a feature of double quoted string literals and regex literals;
they have no thing to do with regular expressions. If you have one in your
regular expression, it's an error.

That said, the documentation mentioned by the OP could definitely make this
clearer.

- Eric

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About