I have the following function which is supposed to read a .html file and search for <input> tags, and inject a <input type='hidden'> tag into the string to be shown into the page.
However, that condition is never met:( e.g the if statement is never executed. ) What’s wrong with my regex?
def print_choose( params, name ):
filename = path + name
f = open( filename, 'r' )
records = f.readlines()
print "Content-Type: text/html"
print
page = ""
flag = True
for record in records:
if re.match( '<input*', str(record) ) != None:
print record
page += record
page += "<input type='hidden' name='pagename' value='psychology' />"
else:
page += record
print page
Thank you
re.matchstarts at the very first char in the string. Are you sure you don’t wantre.search, which can match patterns in the middle of your string?