Matching Newlines with the Dot Character

>>> noNewlineRegex =re.compile('.*')>>> noNewlineRegex.search('Serve the public trust.\nProtect the innocent.
\nUphold the law.').group()'Serve the public trust.'>>> newlineRegex =re.compile('.*',re.DOTALL)>>> newlineRegex.search('Serve the public trust.\nProtect the innocent.
\nUphold the law.').group()'Serve the public trust.\nProtect the innocent.\nUphold the law.'

>>> noNewlineRegex = re.compile('.*')
>>> noNewlineRegex.search('Serve the public trust.\nProtect the innocent.
\nUphold the law.').group()
'Serve the public trust.'
>>> newlineRegex = re.compile('.*', re.DOTALL)
>>> newlineRegex.search('Serve the public trust.\nProtect the innocent.
\nUphold the law.').group()
'Serve the public trust.\nProtect the innocent.\nUphold the law.'

Strings Substitution with Regular Expression

>>> namesRegex =re.compile(r'Agent \w+')>>> namesRegex.sub('CENSORED','Agent Alice gave the secret documents to Agent Bob.')'CENSORED gave the secret documents to CENSORED.'