Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex OR'ing

by Fastolfe (Vicar)
on Jul 28, 2000 at 19:13 UTC ( [id://24876]=note: print w/replies, xml ) Need Help??


in reply to Regex OR'ing

Why not try something like this:
$var =~ /^(?:regex(catch_this))?$/
Anchor it at the start and end of the line (or however you want to anchor the regexp so as to determine where your "absent" or "present" boundaries are), and make the inner grouping optional. If it matches, $1 will either contain "catch this" or be undefined.

This method is more useful when you want to try to match something (and the absense of something) in the middle of a line. You don't have to anchor it at the start and end of the line.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found