0

我想使用 grep 通过正则表达式在文件中查找文本。这是我要查找的文本,右括号前的空格在哪里:

{if sometexthere }

我的命令是:

grep -E -n "\{if[^\}]*[\s+]+\}" mydir/*

但它发现在右括号之前没有空格的行,例如

{if sometexthere}
4

2 回答 2

0

这应该有效:

grep -E "\{if[^\}]*?\s+\}"
于 2013-08-13T06:34:06.117 回答
0

您似乎使正则表达式变得不必要地复杂。尝试:

grep "{if[^}]*\s}$" filename
于 2013-08-13T06:34:33.393 回答