for line in open('file'):
    if 'form action' in line:
        line = line.rstrip()
a = line.split('<form action="')
a[-1] = '"newlogin" ' + a[-1].split()[-1]
How to search for a word and then replace text after it using regular expressions in python?