Python and Regular Expressions

Richard Lamboj richard.lamboj at bilcom.at
Wed Apr 7 10:37:31 CEST 2010


Hello,

i want to parse this String:

version 3.5.1 {

	$pid_dir = /opt/samba-3.5.1/var/locks/
	$bin_dir = /opt/samba-3.5.1/bin/

	service smbd {
		bin = ${bin_dir}smbd -D
		pid = ${pid_dir}smbd.pid
	}
	service nmbd {
		bin = ${bin_dir}nmbd -D
		pid = ${pid_dir}nmbd.pid
	}
	service winbindd {
		bin = ${bin_dir}winbindd -D
		pid = ${pid_dir}winbindd.pid
	}
}

version 3.2.14 {

	$pid_dir = /opt/samba-3.5.1/var/locks/
	$bin_dir = /opt/samba-3.5.1/bin/

	service smbd {
		bin = ${bin_dir}smbd -D
		pid = ${pid_dir}smbd.pid
	}
	service nmbd {
		bin = ${bin_dir}nmbd -D
		pid = ${pid_dir}nmbd.pid
	}
	service winbindd {
		bin = ${bin_dir}winbindd -D
		pid = ${pid_dir}winbindd.pid
	}
} 

Step 1:

version 3.2.14 {

	$pid_dir = /opt/samba-3.5.1/var/locks/
	$bin_dir = /opt/samba-3.5.1/bin/

	service smbd {
		bin = ${bin_dir}smbd -D
		pid = ${pid_dir}smbd.pid
	}
	service nmbd {
		bin = ${bin_dir}nmbd -D
		pid = ${pid_dir}nmbd.pid
	}
	service winbindd {
		bin = ${bin_dir}winbindd -D
		pid = ${pid_dir}winbindd.pid
	}
} 

Step 2:
	service smbd {
		bin = ${bin_dir}smbd -D
		pid = ${pid_dir}smbd.pid
	}
Step 3:
	$pid_dir = /opt/samba-3.5.1/var/locks/
	$bin_dir = /opt/samba-3.5.1/bin/

Step 4:
		bin = ${bin_dir}smbd -D
		pid = ${pid_dir}smbd.pid

My Regular Expressions:
version[\s]*[\w\.]*[\s]*\{[\w\s\n\t\{\}=\$\.\-_\/]*\}
service[\s]*[\w]*[\s]*\{([\n\s\w\=]*(\$\{[\w_]*\})*[\w\s\-=\.]*)*\}

I think it was no good Solution. I'am trying with Groups:
(service[\s\w]*)\{([\n\w\s=\$\-_\.]*)
but this part makes Problems: ${bin_dir}

Kind Regards

Richi



More information about the Python-list mailing list