python regular expression to split paragraphs

前端 未结 5 636
执笔经年
执笔经年 2021-01-19 01:40

How would one write a regular expression to use in python to split paragraphs?

A paragraph is defined by 2 linebreaks (\\n). But one can have any amount of spaces/ta

5条回答
  •  死守一世寂寞
    2021-01-19 02:27

    Unfortunately there's no nice way to write "space but not a newline".

    I think the best you can do is add some space with the x modifier and try to factor out the ugliness a bit, but that's questionable: (?x) (?: [ \t\r\f\v]*? \n ){2} [ \t\r\f\v]*?

    You could also try creating a subrule just for the character class and interpolating it three times.

提交回复
热议问题