问题描述
我知道另一个问题,该问题非常相似,但是对于由于某些原因我仍然遇到问题.
I am aware of another question that is quite similar, but for some reason I'm still having problems.
我有一个GC日志,我正在尝试修剪包含在[]
中的Tenured部分.
I have a GC log that I'm trying to trim out the Tenured section enclosed in []
.
63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs]
我申请s/\[Tenured:.*\]//
非常期望,结果会在行的其余部分被贪婪地修剪:
And quite expectantly, the result is trimmed greedily through the remainder of the line:
63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546:
因此,让我们尝试不贪婪地不将右括号与s/\[Tenured:[^\]]*\]//
匹配,但可惜没有匹配,sed跳过了这一行,产生了相同的原始输出:
So let's try and be non-greedy not match a closing right bracket with s/\[Tenured:[^\]]*\]//
but alas no match is made and sed skips over the line, producing the same original output:
63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs]
如何非贪婪地匹配和替换该部分?谢谢,
How do I non-greedily match and replace that section? Thanks,
推荐答案
几乎:s/\ [Tenured:[^]] * \]//
Almost: s/\[Tenured:[^]]*\]//
手册说:
即在这种情况下,不需要反斜杠.
i.e. No backslash is required in this context.
- Raz
这篇关于sed regex改为非贪婪替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!