[Tutor] Expression matching

Sharriff Aina NHYTRO@compuserve.com
Wed, 9 May 2001 07:56:03 -0400


Message text written by Remco Gerlich
>You also needed \\s in the second regex that you had in the first post o=
f
the thread, for the same reason.


Thanks Remco! I tried that too, but alas:


import re

htmlblock =3D '<span>ff<td><img src>sasa<b><img src=3D"ksksk.jpg">nn<br>j=
h<img
src=3D"c:\ten\ten">'
imageexpr =3D re.compile('<img?\\s+.*?>') # non-greedy
allimagetags =3D imageexpr.findall(htmlblock)
print allimagetags
>>>['<img src>', '<img src=3D"ksksk.jpg">', '<img src=3D"c:\011en\011en">=
']
## ???


>All of this won't be a problem if you read in the HTML from some file,
instead of writing it as a literal string in Python.
<
Yes I know, a pain, the problem is I=B4m fetching the HTML from an HTML
textfield per CGI in realtime, I=B4ll continue exploring


Sharriff

Thanks