尝试获取正确的regexp语法以匹配标记的行(使用*):
#32 0 0 A [2] *
#13 3 2 A [1]
#44 1 2 A [2]
#44 0 0 A [1]
#44 0 0 A [2] *
#44 0 0 B [2] *
我想要的是包含“0 0”的行和在“[2]”之后的某处。任何字符都可以出现在这两个规则之前,之间或之后。
这就是我今天所拥有的,它找到了第一部分:
#.. 0 0
我如何完成它?
此外,如果有人想像我这样的正则表达式新秀分享一个好的网址,我会更加感激!
答案 0 :(得分:1)
`我想要的是,包含“0 0”的行和“[2]”之后的某个地方。任何角色都可以在之前,之间发生
您可以使用此正则表达式:
^#[0-9]{2} 0 0.*?\[2\]
<强>解释强>
^ assert position at start of the string
# matches the character # literally
[0-9]{2} match a single character present in the list below
Quantifier: Exactly 2 times
0-9 a single character in the range between 0 and 9
0 0 matches the characters 0 0 literally
.*? matches any character (except newline)
Quantifier: Between zero and unlimited times, as few times as possible, expanding as needed [lazy]
\[ matches the character [ literally
2 matches the character 2 literally
\] matches the character ] literally
答案 1 :(得分:0)
以下内容如何:
echo '#32 0 0 A [2]
#13 3 2 A [1]
#44 1 2 A [2]
#44 0 0 A [1]
#44 0 0 A [2]
#44 0 0 B [2]' | grep -E '.*0 0.*\[2\].*'
答案 2 :(得分:0)
您可以使用:
#.. 0 0.*\[2\].*