【发布时间】:2021-12-22 02:41:53
【问题描述】:
我有一个字符串:
s=
"(2021-06-29T10:53:42.647Z) [Denis]: hi
(2021-06-29T10:54:53.693Z) [Nicholas]: TA FOR SHOWING
(2021-06-29T11:58:29.053Z) [Nicholas]: how are you bane
(2021-06-29T11:58:29.053Z) [Nicholas]:
(2021-06-29T11:58:29.053Z) [Nicholas]: #END_REMOTE#
(2021-06-30T08:07:42.029Z) [Denis]: VAL 01JUL2021
(2021-06-30T08:07:42.029Z) [Denis]: ##ENDED AT 08:07 GMT##"
我想从中提取文本。预期输出为:
comments=['hi','TA FOR SHOWING','how are you bane',' ','#END_REMOTE#','VAL 01JUL2021','##ENDED AT 08:07 GMT##']
我试过的是:
comments=re.findall(r']:\s+(.*?)\n',s)
正则表达式运行良好,但我无法将空白文本设为''
【问题讨论】:
-
你必须排除匹配
]像]:\s+([^]\n]*)$ -
能否提供您用于处理文本的代码?您提供的字符串文字 does not compile.
-
我注意到你没有接受任何your questions 的问题你能复习一下问题吗,如果发布的答案成功了,请看What should I do when someone answers my question?
-
@Thefourthbird 我做过...肯定会为其他人做的。
标签: python-3.x regex string