fork download
  1. import re
  2. import sys
  3.  
  4. text = sys.stdin.read()
  5.  
  6. # using str.find():
  7. result = text[:text.find('\n\n') + 1]
  8.  
  9. # using re
  10. result2 = re.match(r'(.*?)$^$', text, flags=re.DOTALL | re.MULTILINE).group(1)
  11.  
  12.  
  13. # check that the result is the same
  14. for r in [result, result2]:
  15. print(repr(r))
  16. assert result == result2
  17.  
Success #stdin #stdout 0.02s 5764KB
stdin
This is a matched string_1.
This is a matched string_22.

Do not match this line.
stdout
'This is a matched string_1.\nThis is a matched string_22.\n'
'This is a matched string_1.\nThis is a matched string_22.\n'