fork download
  1. import re
  2. combined = r'^BRN.*?(?:paid|to)\s(?![A-Za-z\s]*\bself\b)([A-Za-z\s]+)'
  3. narrations = ['BRN CLG-CI IQ PAID ROHIT SINGH','BRN-TO CASH SELF']
  4.  
  5. for narration in narrations:
  6. print('-------',narration,sep='\n')
  7. match = re.findall(combined, narration, flags=re.I)
  8. if match:
  9. result = list(filter(None, match))
  10. print( result[0] )
  11. else:
  12. print( '' )
Success #stdin #stdout 0.02s 9424KB
stdin
Standard input is empty
stdout
-------
BRN CLG-CI IQ PAID ROHIT SINGH
ROHIT SINGH
-------
BRN-TO CASH SELF