post
poster: toraton
description: python regexp - broken
language: Python
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    def replace_loops(self, txt=''):
        """
        Replaces 'for' loops with the values requested.
        Returns nothing.
        """

        #p = re.compile('\{%\s*for\s+(.*?)\s+in\s+(.*?)\s*%\}', re.MULTILINE)
        p = re.compile('(for)', re.M | re.I);
        m = p.match(txt)
        print "for %s in %s" % (m.group(1), m.group(1))

The value of txt is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>{{ site_title }} - {{ site_description }}</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link type="text/css" rel="StyleSheet" href="{{ site_css }}" />
  </head>
  <body>
    <div id="page_title">{{ site_title }}</div>
    {{ navigation_bar }}
    {% for entry in posts %}
    <div class="entry">
      <span class="entry_title">entry_title</span>
      <span class="entry_details">
        posted by
        <span class="entry_author">entry_author</span>
        on
        <span class="entry_date">entry_date</span>
      </span>
      <span class="entry_content">entry_content</span>
    </div>
    <div class="entry">
      <span class="entry_title">entry_title</span>
      <span class="entry_details">
        posted by
        <span class="entry_author">entry_author</span>
        on
        <span class="entry_date">entry_date</span>
      </span>
      <span class="entry_content">entry_content</span>
    </div>
  </body>
</html>