Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Matching multiple patterns with regex

by graff (Chancellor)
on Oct 31, 2015 at 15:38 UTC ( [id://1146578]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Matching multiple patterns with regex
in thread Matching multiple patterns with regex

Actually, I wouldn't recommend quotemeta in tasks like this. It's seldom or never the case that regex-magic characters will be needed as literals in the patterns being conjoined, but even if this comes up, it can still be better to escape them explicitly as needed (when assigning to the array), and allow some strings to use regex-magic where appropriate:
my @fields = ('From: ', 'Subject: ', 'Thread-\w+: ', 'What-if-there\'s +-a-qmark\?'); # 3rd element matches "Thread-Topic: ", "Thread-Index: ", etc.
Obviously, in a context where strings are coming from a potentially tainted source (i.e. not from the source code itself), one must weigh the relative risk/benefit and coding-effort/ease-of-use trade-offs of prohibiting vs. allowing (and taint-checking) regex metacharacters in applications like this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found