[Tutor] re question
Jonathan Hayward http://JonathansCorner.com
jonathan.hayward at pobox.com
Fri Aug 8 18:32:44 EDT 2003
I'm trying to use regexps to find the contents of all foo tags. So, if I
gave the procedure I'm working on an HTML document and asked for
"strong" tags, it would return a list of strings enclosed in <strong>
</strong> in the original.
I'm having trouble with the re; at the moment the re seems to return
only the first instance. What am I doing wrong?
def get_tag_contents_internal(self, tag, file_contents):
result = []
# At present only matches first occurrence. Regexp should be
worked on.
my_re = re.compile(".*?(<" + tag + ".*?>(.*?)</" + tag + \
".*?>.*?)+.*?", re.IGNORECASE)
if my_re.match(file_contents) != None:
result = my_re.match(file_contents(group(2))
return result
--
++ Jonathan Hayward, jonathan.hayward at pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com
More information about the Tutor
mailing list