Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个 python 脚本,它从 sdict 中检索值作为字符串值。许多返回的值包含取决于 sdict 的时间戳,这有点烦人。
例如。<2006-12-20 00:10:24 Cattle is a tree>
<2006-12-20 00:10:24 Cattle is a tree>
我一辈子都无法弄清楚如何2006-12-20 00:10:24从返回值中删除 。有没有人有任何想法?我在想我可以去掉 - 字符之间的任何东西。但是,返回的值通常包含 - 贯穿始终。
2006-12-20 00:10:24
这是使用正则表达式的好选择。
>>> import re >>> s = '<2006-12-20 00:10:24 Cattle is a tree>' >>> re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} ', '', s) '<Cattle is a tree>'