回复quirement:using regex 只想从输入列表中获取特定字符串,即“-”和“*”符号之间的字符串。下面是代码片段
ZTon = ['one-- and preferably only one --obvious', " Hello World", 'Now is better than never.', 'Although never is often better than *right* now.']
ZTon = [ line.strip() for line in ZTon]
print (ZTon)
r = re.compile(".^--")
portion = list(filter(r.match, ZTon)) # Read Note
print (portion)
预期响应:
['and preferably only one','right']
印刷品:
使用正则表达式
相关问题 更多 >
编程相关推荐