regular expression not behaving as expected - Python
Posted
by
philippe
on Stack Overflow
See other posts from Stack Overflow
or by philippe
Published on 2012-10-24T22:57:40Z
Indexed on
2012/10/24
23:00 UTC
Read the original article
Hit count: 179
python
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
© Stack Overflow or respective owner