Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^11: Bind zone file search

by Kenosis (Priest)
on Sep 26, 2012 at 20:56 UTC ( #995872=note: print w/ replies, xml ) Need Help??


in reply to Re^10: Bind zone file search
in thread Bind zone file search

The m modifier will not help here. I (incorrectly) assumed that there was only one zone stanza per file. Processing multiple zone stanzas requires globally matching and preventing part of the regex from being 'greedy.' Try the following line:

$hash{$1} = $2 while $data =~ /zone\s+"([^"]+)".+?masters\s+{[\s#\/]*([a-zA-Z0-9.- +]+)[\s#\/;]*}/sg;

You'll note that: while has replaced if, there's a ? right after the + preceding masters, and the globally modifier is used.

while is used to process all matches; the ? prevents the regex from being 'greedy,' so it doesn't start the match at the beginning of a zone stanza and end the match with the last stanza.


Comment on Re^11: Bind zone file search
Select or Download Code
Re^12: Bind zone file search
by ranceh (Initiate) on Sep 27, 2012 at 13:53 UTC

    This is really close, but not quite right.

    This regex is matching commented zone directives and if the comment is found after the real one is overwriting good answers for bad ones.

    I need to avoid commented stanzas. Since commented stanzas include comment characters prior to the match of zone, I think I need a way to ensure that matches on the word zone. Am I thinking correctly?

      By "commented," do you mean those containing either the "//" or "#" characters? Do you want to avoid all zone stanzas that contain those characters and use only those zone stanzas that don't contain those comment characters, i.e., "//" and "#"?

        right, I need to avoid stanzas that begin with the // or #

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-07-14 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls