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

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

Thread Previous
From:
Eric Brine
Date:
October 15, 2014 05:24
Subject:
Re: Expected behavior of \Q inside a bracketed character class?
Message ID:
CALJW-qE=N9meDphg=PQ3ZEYJNk0x5XY6+QmZk4qNz9fzO4b5Ug@mail.gmail.com
On Wed, Oct 15, 2014 at 1:16 AM, Eric Brine <ikegami@adaelis.com> wrote:

> On Wed, Oct 15, 2014 at 12:30 AM, Marco Moreno <mmoreno@pobox.com> wrote:
>
>> Using a \Q inside a bracketed character class, should this return true or
>> false?  This returns "false" for my 5.18.2 and 5.20.0 installs.
>>
>> perl -e 'print "foo"=~ /\Q[a-z]\E/ ? "true" : "false"'
>>
>
> It's not inside a bracketed class, not that it matters. \Q..\E doesn't
> know anything about regular expressions. It escapes non-word characters
> after interpolating, so
>
> /\Q[a-z]\E/
>
> is the same thing as
>
> /\[a\-z\]/
>

[Sent by accident. Continuing...]

So that makes the documentation wrong/unclear. \Q..\E don't work in
character class as the documentation says, but only because it's impossible
actually put one in a character class. Its effect already happened as part
of the building the string before there even was a character class.

Thread Previous


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