Find shortest matches between two strings

后端 未结 4 1257
走了就别回头了
走了就别回头了 2020-11-22 16:30

I have a large log file, and I want to extract a multi-line string between two strings: start and end.

The following is sample from the

4条回答
  •  鱼传尺愫
    2020-11-22 17:06

    This regex should match what you want:

    (start((?!start).)*?end)
    

    Use re.findall method and single-line modifier re.S to get all the occurences in a multi-line string:

    re.findall('(start((?!start).)*?end)', text, re.S)
    

    See a test here.

提交回复
热议问题