【发布时间】:2013-04-03 09:24:31
【问题描述】:
我2天前刚开始学习python,如果我犯了明显的错误,请见谅
strings: "brake break at * time" --> ["at","time"]
"strang strange I felt very *" --> ["very",""]
我想在 * 之前和之后得到消息
我的尝试:
re.match(r"(?P(first_word)\w+) ('_*_') (?P(first_word)\w+)",strings).group('first_word')
获取第一个单词
re.match(r"(?P(first_word)\w+) ('_*_') (?P(first_word)\w+)",strings).group('last_word')
最后一个字
错误:无需重复
【问题讨论】:
-
你试过
.split('*'),因为它是你不想要的*
标签: python string pattern-matching matching split