import re re.sub('X', 'Mr. Smith', 'attn: X\n\nDear X,\n') re.subn('X', 'Mr. Smith', 'attn: X\n\nDear X,\n') print re.sub('X', 'Mr. Smith', 'attn: X\n\nDear X,\n') re.sub('[ae]', 'X', 'abcdef') re.subn('[ae]', 'X', 'abcdef') # Splitting (on Delimiting Pattern) with split() re.split(':', 'str1:str2:str3')