title: Regex vs readline for text processing
body: <p>I have a text to process (router output) and generate useful data structure (dictionary having keys as iface name and values as packet counts) from it. I have two approaches to do the same task. I would like to know which one should I use for efficiency and which one looks more prone to fail for bigger data samples.</p>
  
  <p>Readline1 gets a list from readline and processes output and writes into the dictionary with key as interface name and values as next three items. </p>
  
  <p>Readline2 uses re module and match the groups and from groups it writes to dictionary keys and values. </p>
  
  <p>input self.output to these functions will be something like this:</p>
  
  <pre><code>message = 
  """
  Interface 1/1\n\t
      input : 1234\n\t
      output : 3456\n\t
      dropped : 12\n
  \n
  Interface 1/2\n\t
      input : 7123\n\t
      output : 2345\n\t
      dropped : 31\n\t
  """
  
  def ReadLine1(self):
      lines = self.output.splitlines()
      for index, line in enumerate(lines):
          if "Interface" in line:
              valuelist = []
              for i in [1,2,3]:
                  valuelist.append((lines[index+i].split(':'))[1].strip())
              self.IFlist[line.split()[1]] = valuelist
      return self.IFlist
  
  def Readline2(self):
      #print repr(self.output)
      n = re.compile(r"\n*Interface (./.)\n\s*input : ([0-9]+)\n\s*output : ([0-9]+)\n\s*dropped : ([0-9]+)",re.MULTILINE|re.DOTALL)
      blocks = self.output.split('\n\n')
      for block in blocks:
          m_object = re.match(n, block)
          self.IFlist[m_object.group(1)] = [m_object.group(i) for i in (2,3,4)]
  </code></pre>