我正在尝试转义这个序列中的字符串
[0m[ERROR] [1585551547.349979]: Failed to create bragfiles/downtimer/fight100/2020-03-27. Error: 550 Create directory operation failed.
[ERROR] [1585551547.349979]: Failed to create bragfiles/downtimer/fight100/2020-03-27. Error: 550 Create directory operation failed.
及
[32m[INFO] [2020-03-29 23:58:50.607198] TaskManager.poll: system has no current task.[0m
[INFO] [2020-03-29 23:58:50.607198] TaskManager.poll: system has no current task.
再加上偶尔的双重符号
"[0m[32m[INFO] [2020-03-29 23:58:34.695268] Polling for updates from the server for fight100...[0m"
"[INFO] [2020-03-29 23:58:34.695268] Polling for updates from the server for fight100..."
我以前遇到过这种情况,但在我的情况下似乎不正确:
我一直在尝试各种各样的\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])
变体,但我认为这不合适
但到目前为止,我尝试过的正则表达式似乎都不够通用
(一个或两个(颜色转义序列))后跟(方括号内的大写字母字符)(正向前瞻)
使用此字符串:
正向前瞻可防止捕获最后一位
如果需要删除指定前景和背景色的序列,如
将
pat = r'''((\[\d+m){1,})(?=\[[A-Z]+\])'''
用于(一个或多个)而不是(一个或两个)如果有这样的东西
使用
pat = r'''(\[([01];)?\d+m){1,}(?=\[[A-Z]+\])'''
您的一些示例字符串在字符串的中间显示了颜色序列,您所需的输出显示它们被替换-与您的注释相反
这些模式将从字符串的中间删除序列
相关问题 更多 >
编程相关推荐