Using a regular expression here is overkill. .replace()
returns the line unchanged if the replacement text is not present at all, so there is no need to test even.
To replace data in a file, in place, it is easier to use the fileinput module:
import fileinput
for line in fileinput.input('names.txt', inplace=True):
line = line.replace('samuel', 'boxer')
print line.strip()