问题标签 [gnu-sed]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
31 问题
0
投票
2
回答
132
浏览
regex - 除 [ 和 ] 字符外的空格分隔符的正则表达式
我认为我对正则表达式的使用非常好,但是这个看起来非常棘手。
我想修剪所有空格,除了 "" 和 [] 字符之间的空格。
我使用了这个正则表达式("[^"]*"|\S+)\s+,但确实将我的日志的[06/Jan/2021:17:50:09 +0300]部分分成了两个块。
这是我的整个日志行:
结果我使用 sed 命令基于我的正则表达式(用逗号替换空格):
最后我想要的结果: