Python 3 regex?

Ian hobson42 at gmail.com
Mon Jan 12 14:48:18 EST 2015


On 12/01/2015 18:03, Jason Bailey wrote:
> Hi all,
>
> I'm working on a Python _3_ project that will be used to parse ISC 
> DHCPD configuration files for statistics and alarming purposes (IP 
> address pools, etc). Anyway, I'm hung up on this one section and was 
> hoping someone could provide me with some insight.
>
> My script first reads the DHCPD configuration file into memory - 
> variable "filebody". It then utilizes the re module to find the 
> configuration details for the wanted "shared network".
>
Hi Jason,

If you actually look at the syntax of what you are parsing, it is very 
simple.

My recommendation would be to write a recursive decent parser for your 
files.

That way will be easier to write, much easier to modify and almost 
certainly faster that a RE solution - and it can easily give you all the 
information in the file thus future proofing it.

'Some people, when confronted with a problem, think "I know, I'll use 
regular expressions." Now they have two problems.' -  Jamie Zawinski.

Regards

Ian





More information about the Python-list mailing list