Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Multiple regexs into single combined regex using lookaheads

by tybalt89 (Prior)
on Apr 16, 2018 at 15:16 UTC ( #1212997=note: print w/replies, xml ) Need Help??


in reply to Multiple regexs into single combined regex using lookaheads

#!/usr/bin/perl use strict; use warnings; for (<DATA>) { chomp; print "Match: $_\n" if /^(?=.*name=bob)(?!.*flags=.*?cat.*?;)/; } __DATA__ name=bob;flags=human;age=10 name=tiddles;flags=cat,black;age=3 name=bob;flags=cat,white;age=6

Replies are listed 'Best First'.
Re^2: Multiple regexs into single combined regex using lookaheads
by mxb (Pilgrim) on Apr 17, 2018 at 08:10 UTC

    Ahh! I see you've added .* before each match. Many thanks for the working example.

    Am I correct in thinking that both lookaheads must be anchored in the same position (which is ^ in the example above?)

    Because they are both anchored at the start of the string, each lookahead can match multiple of any character before the string I'm looking for (e.g. name=bob) as this allows each lookahead to 'seek' forward independently, and succeed at a different point in the string?

      In answer to your two questions: yes and yes.


      Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2020-10-25 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?