我想尝试一下grep使用正则表达式的命令,发现它们的行为与我的预期不同。例如,考虑temp具有以下内容的文件
helloworld
hello_world
hello world
hello how are you world
hello wor ld
hello_*_..world
helloEworld
Run Code Online (Sandbox Code Playgroud)
当我跑步时
grep 'hello.*world' temp
Run Code Online (Sandbox Code Playgroud)
它返回
helloworld
hello_world
hello world
hello how are you world
hello_*_..world
helloEworld
Run Code Online (Sandbox Code Playgroud)
正如预期的那样。但当我跑步时
grep 'hello.+world' temp
Run Code Online (Sandbox Code Playgroud)
它什么也不返回...虽然当我\之前添加时+
grep 'hello.\+world' temp
Run Code Online (Sandbox Code Playgroud)
它返回正确的输出
hello_world
hello world
hello how are you world
hello_*_..world
helloEworld
Run Code Online (Sandbox Code Playgroud)
在上一个命令中添加\ before并运行*
grep 'hello.\*world' temp
Run Code Online (Sandbox Code Playgroud)
什么也没返回...
为什么grep 'hello.+world' temp如果没有 则该命令不起作用\?
为什么它恰恰相反*?
我应该什么时候使用\?