代码如下:
#coding=utf-8
import re
str = "The output is\n"
str += "1) python\n"
str += "A dynamic language\n"
str += "easy to learn\n"
str += "2) C++\n"
str += "difficult to learn\n"
str += "3244) PHP\n"
str += "eay to learn\n"
pattern = r'^[1-9]+\) .*'
print re.findall(pattern,str,re.M)
输出是
['1) python', '2) C++', '3244) PHP']
但是,我想像这样拆分它:
['1) python\n'A dynamic language\n easy to learn\n' 2) C++\n difficult to learn\n', '3244) PHP\n easy to learn\n']
也就是说,忽略不以“number)”开头的第一行,当遇到一个数字时,直到下一行以“number)”开头的以下行被认为是同一组。我应该如何重写模式?