Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Parens mess up regex substitute

by davido (Archbishop)
on Jan 26, 2012 at 06:43 UTC ( #950030=note: print w/ replies, xml ) Need Help??

in reply to Parens mess up regex substitute


PATTERN may contain variables, which will be interpolated every time the pattern search is evaluated, except for when the delimiter is a single quote.

Parens aren't the only thing you have to look out for. '.' (dot) will be treated as a meta-character that matches anything except for newline. [] square brackets will be treated like character classes, and so on through the entire list of regexp pattern tokens. quotemeta or \Q and \E are not just quirks providing a lucky solution, this sort of situation is on the short list of reasons for quotemeta and \Q\E to exist.

In perldoc -f quotemeta you'll read, "quotemeta (and \Q ... \E ) are useful when interpolating strings into regular expressions, because by default an interpolated variable will be considered a mini-regular expression. I wouldn't call it an anomaly, it's just how Perl is designed.

perlop contains a good crash course on how interpolation works. The sections to look for start with Quote and Quote-like Operators, and continue through the end of "Gory details of parsing quoted constructs".


Comment on Re: Parens mess up regex substitute
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950030]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2015-12-01 18:20 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (24 votes), past polls