help with cr in reg exp...

G

GrelEns

hello,

i had a trouble with re that i didn't understand (this is a silly example to
show, to parse html i use sgmllib) :
having this string :
<input type="text" name="title" size="1." value="test...">
<br>
<a href="help.php">help</a>
</form>"""

why do i get :
[]

while i was expected this kind of behaviour :
['form name="test" method="post" action="test.php">\n<input type="text"
name="title" size="1." value="test...">\n<br>\n<a href="help.php">help</a>']

which what i nearly get with :p.findall(s.replace('\n', ''))
['<form name="test" method="post" action="test.php"><input type="text"
name="title" size="1." value="test..."><br><a href="help.php">help</a> ']

it looks like \n isn't matched by . (dot)* in my re while i though (and
need) it should, i must be missing something.

thanks!
 
P

Peter Otten

GrelEns said:
hello,

i had a trouble with re that i didn't understand (this is a silly example
to show, to parse html i use sgmllib) :
having this string :
<input type="text" name="title" size="1." value="test...">
<br>
<a href="help.php">help</a>
</form>"""

why do i get :
[]

while i was expected this kind of behaviour :
['form name="test" method="post" action="test.php">\n<input type="text"
name="title" size="1." value="test...">\n<br>\n<a
href="help.php">help</a>']

which what i nearly get with :p.findall(s.replace('\n', ''))
['<form name="test" method="post" action="test.php"><input type="text"
name="title" size="1." value="test..."><br><a href="help.php">help</a> ']

it looks like \n isn't matched by . (dot)* in my re while i though (and
need) it should, i must be missing something.

thanks!

Try re.compile(yourpattern, re.DOTALL)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top