match()の場合
import re s = "lesson1regular expression-How to use re module-" r = re.compile("(^lesson\d+)(.*)(-.*?-)", re.M) a = r.match(s) atuple = a.groups() alist = list(atuple) print alist
findallの場合
import re s = "lesson1regular expression-How to use re module-" r = re.compile("(^lesson\d+)(.*)(-.*?-)", re.M) a = r.findall(s) alist = list(a[0]) print alist
結果
['lesson1', 'regular expression', '-How to use re module-']
こんな感じでいいのかしらん?