title: Python Regex help required
body: <p>I am trying to extract data from a text file.
  For ex in line '35 of Jon 2013 trans. (P) ' I am trying to extract (35, 2013, (P)). </p>
  
  <p>In this 35 is document number and 2015 is document year, (P) denotes priority document. </p>
  
  <p>Document Numbers are followed by Document year and they have (P) in end if document is of high priority. </p>
  
  <p>There is possibility that a document is not of high priority and it will not contain (P) at end. 
  ex - '31 of Sansa 2014 filled' 
  in this I want to extract (31,2014,'')</p>
  
  <p>I have a string that contain information of document. The problem is that the string is concatenated and in a single string there is information of multiple document.  </p>
  
  <p>line = '35 of Jon 2013 trans. (P) 31 of Sansa 2014 filled 3232 of Arya 2014 empty 345 of Bran 2011 sealed, (P) ' </p>
  
  <p>I have written the following code but it does not function correctly.</p>
  
  <pre><code>rgx = r'(\d{1,9})\s* OF \s*[A-Za-z]+\s*([1,2]\d{3}).*?(\(P\))?'
  rgx2 = r'(\d{1,9})\s* OF \s*[A-Za-z]+\s*([1,2]\d{3}).*?(\(P\))'
  line = '35 of Jon 2013 trans. (P) 31 of Sansa 2014 filled 3232 of Arya 2014 empty 345 of Bran 2011 sealed, (P)'
  
  x = re.findall(rgx, line, re.IGNORECASE)
  for i in x:
      print i
  print 'Output by rgx2'
  x = re.findall(rgx2, line, re.IGNORECASE)
  for i in x:
      print i
  </code></pre>
  
  <p>Output generated by this code : -</p>
  
  <pre><code>('35', '2013', '')
  ('31', '2014', '')
  ('3232', '2014', '')
  ('345', '2011', '')
  Output by rgx2
  ('35', '2013', '(P)')
  ('31', '2014', '(P)') 
  </code></pre>
  
  <p>While the first regex is able to catch document id and document year correctly but it fails to extract (P) type as I am using "(P)?". 
  Problem with second regex is that I am using ".*?(P)" to find P type and it results into wrong data. </p>
  
  <p>The correct data output which I want is </p>
  
  <pre><code> ('35', '2013', '(P)')
   ('31', '2014', '')
   ('3232', '2014', '')
   ('345', '2011', '(P)')
  </code></pre>
  
  <p>Can anyone suggest a better regex.
  Please Help ! </p>