title: Read only lines that contain certain specific string and apply regex on them
body: <p>Here's my code: I have a script that reads a file but in my file not all the lines are similar and I'd like to extract informations only from lines that have <code>I DOC O:</code>.</p>
  
  <p>I've tried with an if condition but it still doesn't work when there are lines where regex aren't matching:  </p>
  
  <pre><code>#!/usr/bin/env python 
  
  # -*- coding: utf-8 -*-
  
  import re 
  
  def extraire(data):
      ms = re.match(r'(\S+).*?(O:\S+).*(R:\S+).*mid:(\d+)', data) # heure &amp; mid 
      return {'Heure':ms.group(1), 'mid':ms.group(2),"Origine":ms.group(3),"Destination":ms.group(4)}
  
  tableau = []  
  
  fichier = open("/home/TEST/file.log")
  f = fichier.readlines() 
  for line in f: 
      if (re.findall(".*I Doc O:.*",line)):     
      tableau = [extraire(line) for line in f ]
  
  print tableau
  fichier.close()
  </code></pre>
  
  <p>And here's an example of some lines of my file here i want first and fourth lines..: </p>
  
  <pre><code>01:09:25.258 mta         Messages       I Doc O:NVS:SMTP/alarm@yyy.xx R:NVS:SMS/+654811 mid:6261
  01:09:41.965 mta         Messages       I Rep O:NVS:SMTP/alarmes.techniques@xxx.de R:NVS:SMS/+455451 mid:6261
  01:09:41.965 mta         Messages       I Rep 6261 OK, Accepted (ID: 26)
  08:14:14.469 mta         Messages       I Doc O:NVS:SMTP/alarm@xxxx.en R:NVS:SMS/+654646 mid:6262
  08:14:30.630 mta         Messages       I Rep O:NVS:SMTP/alarm@azea.er R:NVS:SMS/+33688704859 mid:6262
  08:14:30.630 mta         Messages       I Rep 6262 OK, Accepted (ID: 28)
  </code></pre>