I'm trying to get re.sub to replace a pattern specified with a value for example
for lines in f:
pattern='\${2}'+key[0]+'\${2}'
re.search(pattern,lines)
this return the line where the pattern was found. For example this is one of the test returns if got
this is a $$test$$
The problem i'm having is when i do the following
re.sub(pattern,key[1],lines)
nothing happens. What am i missing? For more info key[0]=test and key[1]=replace
so what i'm trying to do is whenever "$$test$$" is encountered it will replace it with "replace". I have no problem finding "$$test$$" but for some reason re.sub isn't replacing it.
'\$'is going to mean just'$'. When someone is reading a string and finds a backslash expects something special or another backslash. If you need many backslashes in a string then you should use use a raw string... - 6502re.subproblems, make sure you are passingre.IGNORECASEas aflags=argument, not thecountargument. - Noumenon