I can't understand re.sub

Mr Zaug matthew.herzog at gmail.com
Sun Nov 29 16:36:57 EST 2015


I need to use re.sub to replace strings in a text file. I can't seem to understand how to use the re module to this end.

result = re.sub(pattern, repl, string, count=0, flags=0);

I think I understand that pattern is the regex I'm searching for and repl is the thing I want to substitute for whatever pattern finds but what is string?

The items I'm searching for are few and they do not change. They are "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template file. They do not appear together on any line and they only appear once on each line.

This should be simple, right?



More information about the Python-list mailing list