Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex bash中带grep的正则表达式_Regex_Bash_Grep - Fatal编程技术网

Regex bash中带grep的正则表达式

Regex bash中带grep的正则表达式,regex,bash,grep,Regex,Bash,Grep,我正在尝试打印包含任意数量的“=”符号的字符串。为此,我在bash中使用以下命令 cat myfile | grep '^.*=+.*$' 我正在写“^”和$作为字符串的开头和结尾 *对于任何字符的任何数字 =+表示一个或多个相等=字符 但它在执行时不显示任何输出 但如果我这么做的话: cat myfile | grep '=' 我得到了想要的输出为什么会这样 我这里缺少什么?您使用的正则表达式不是基本的posix正则表达式。例如,它尝试按字面上的+匹配 你应该尝试使用 cat myfil

我正在尝试打印包含任意数量的“=”符号的字符串。为此,我在bash中使用以下命令

cat myfile | grep '^.*=+.*$' 
我正在写“^”和$作为字符串的开头和结尾

*对于任何字符的任何数字

=+表示一个或多个相等=字符

但它在执行时不显示任何输出

但如果我这么做的话:

cat myfile | grep '='
我得到了想要的输出为什么会这样


我这里缺少什么?

您使用的正则表达式不是基本的posix正则表达式。例如,它尝试按字面上的+匹配

你应该尝试使用

cat myfile | grep-E'^.*=+.*$' E表示扩展正则表达式

Wikipedia对posix basic和扩展正则表达式进行了很好的比较,您还可以看到+在扩展版本中只是一个元字符:

请参见