python - How to add IGNORECASE without Compiling a RE -


instead of using:

var = re.compile('old word',re.ignorecase) 

and using:

var2 = var.sub(r'new word', line) 

how implement ignorecase into:

var = re.sub(r'word',r'word',line) 

use flags kwarg:

re.sub(r'word',r'word',line, flags=re.ignorecase) 

note it's available in 2.7 or later.

http://docs.python.org/2/library/re.html#re.sub


Comments