0

I have a text file and I want to extract a block of text from the starting point till the ending point. The text file looks like below:

01.08.2016 00:00:00 ==================UK==========================
01.08.2016 09:15:34 Market : UK
01.08.2016 09:15:34 From : 01/07/2016
01.08.2016 09:15:34 To : 31/07/2016
01.08.2016 09:15:39 ==================GERMANY==========================

My starting point is ==================UK========================== and ending point is ==================GERMANY==========================

Below is the code I have written but it does not seem to work.

import re

START = '==================UK=========================='
END = '==================GERMANY=========================='

fd = open('export_xml.log', 'r').read()

result = re.search('%s(.*)%s' % (START,END), fd)

print result
Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
Ricky
  • 13
  • 7
  • 1
    `.` won't match newlines unless you set `re.DOTALL`. – Martijn Pieters Aug 12 '16 at 08:02
  • See also http://stackoverflow.com/questions/3534507/python-regex-matching-pattern-over-multiple-lines-why-isnt-this-working, there are many more questions like that. The modifiers are also discussed in the [SO Regex Documentation](http://stackoverflow.com/documentation/regex/5138/regex-modifiers-flags#t=201608120804121686269). – Wiktor Stribiżew Aug 12 '16 at 08:03
  • Thanks Martijn, your answer helped. Thanks again. – Ricky Aug 12 '16 at 09:42

0 Answers0