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:
Marco Moreno
Date:
October 16, 2014 15:04
Subject:
Re: Expected behavior of \Q inside a bracketed character class?
Message ID:
CAJfRpHr+oVa3e=spRBsKwsRRJn=sX_cuXUtMABFyszcfCPaLZg@mail.gmail.com
On Wed, Oct 15, 2014 at 3:18 PM, Eric Brine <ikegami@adaelis.com> wrote:

>
> \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.
>

Thanks for the explanation, Eric.  That helps clarify what's going on (i.e.
 \Q parsing takes place before regex parsing).

However, can you elaborate what you mean by "if you have one (\Q..\E) in
your regular expression, it's an error"?

Isn't that the point of having \Q -- to provide quotemeta() in a regex?
You're not suggesting that this example from the quotemeta() docs is
improper?

my $sentence = 'The quick brown fox jumped over the lazy dog';
my $substring = 'quick.*?fox';
$sentence =~ s{\Q$substring\E}{big bad wolf};

I understand that as part of the parsing process, the \Q..\E no longer
remains part of the compiled regex and should not be considered as such.
Is this what you meant by this?

Marco

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