Grabbing a body of text using regex excluding specific conditions

前端 未结 1 802
旧巷少年郎
旧巷少年郎 2021-01-28 20:33

I\'m using Python regex to grab the body of a parsed email which may contain nothing or may look something like this:

Some coherent sentence.

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 21:00

    You may use

    (?s)\A.*?(?=\n_)
    

    It matches

    • (?s) - re.DOTALL inline flag
    • \A - start of string
    • .*? - any 0+ chars, as few as possible till the first occurrence of
    • (?=\n_) - a newline followed with _ char.

    0 讨论(0)
提交回复
热议问题