Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex OR'ing

by Fastolfe (Vicar)
on Jul 28, 2000 at 19:13 UTC ( #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
Node Status?
node history
Node Type: note [id://24876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2020-01-23 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?