Time for action - suppressing portions of a match

In this example, we'll write a simple grammar for parsing a BIND DNS configuration file. In our regular expressions chapter, we learned out to process a zone file. In this example, we'll extract data from a /etc/named.conf file using PyParsing.

  1. First, we'll create some input data. Create a file named named.conf and copy in the following data. This example leaves off the values found in a named.conf options section for brevity.
    zone "example01.com" IN {
    	type master;
    	file "example01.com.dns";
    	allow-update { none; };
    };
    zone "example02.com" IN {
    	file "example02.com.dns";
    	type master;
    	allow-update { none; };
    };
    
  2. Now, create a Python script named conf_parse.py and enter the following code listing:
    import ...

Get Python 2.6 Text Processing Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.