Python regex, matching pattern over multiple lines.. why isn't this working?

后端 未结 2 1915
渐次进展
渐次进展 2020-11-28 15:19

I know that for parsing I should ideally remove all spaces and linebreaks but I was just doing this as a quick fix for something I was trying and I can\'t figure out why its

2条回答
  •  一个人的身影
    2020-11-28 15:44

    Try re.findall(r"####(.*?)\s(.*?)\s####", string, re.DOTALL) (works with re.compile too, of course).

    This regexp will return tuples containing the number of the section and the section content.

    For your example, this will return [('1', 'ttteest'), ('2', ' \n\nttest')].

    (BTW: your example won't run, for multiline strings, use ''' or """)

提交回复
热议问题