On Thu, May 15, 2008 at 11:22 AM, root <[EMAIL PROTECTED]> wrote: > hi ,i am working to replace three lines in a httpd.conf file using > regular expression
You don't need regex for this, you are replacing plain strings. I would read the entire file, change the strings and write it out again. For example, path = "/root/Desktop/httpd.conf" f = open(path) data = f.read() f.close() for search, replace in [ ('User apache ' , 'User myuser '), ('Group apache','Group myuser'), ('DirectoryIndex\ index.html\ index.html.var','DirectoryIndex\ index.html\ index.html.var\ login.html') ]: data.replace(search, replace) f = open(path, 'w') f.write(data) f.close() This replaces the file in place, if you want to make a backup it will be a little more complex. A few other notes: - don't use 'file' as a variable name, it shadows the builtin file() function - I'm not sure what the \ in your search string are for but they are interpreted as escape characters. If you want a literal \ in the string you have to use two \\ or prefix the string with r to make a raw string. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor