正则表达式星号无法匹配。为什么?

正则表达式星号无法匹配。为什么?

示例来自: Linux 期刊文章

正如本文所预期的那样,前两个示例有效,但第三个示例无效。有人可以解释为什么吗?我在 Ubuntu 22.04.1 和 RHEL9 上都尝试过,结果相同。

我的屏幕:

[primus@rhel9 sandbox]$ cat filename.doc 
The fast dog is fast.
The faster dogs are faster.
A sick dog should see a dogdoc.
This file is filename.doc.
[primus@rhel9 sandbox]$ grep "fast*" filename.doc 
The fast dog is fast.
The faster dogs are faster.
[primus@rhel9 sandbox]$ grep "dogs*" filename.doc 
The fast dog is fast.
The faster dogs are faster.
A sick dog should see a dogdoc.
[primus@rhel9 sandbox]$ grep "*.doc" filename.doc 
[primus@rhel9 sandbox]$ 
[primus@rhel9 sandbox]$ 

但作为扩展的正则表达式,第三个示例有效:

[primus@rhel9 sandbox]$  
[primus@rhel9 sandbox]$ egrep "*.doc" filename.doc  
A sick dog should see a dogdoc.  
This file is filename.doc.  
[primus@rhel9 sandbox]$ grep -E "*.doc" filename.doc   
A sick dog should see a dogdoc.  
This file is filename.doc.  
[primus@rhel9 sandbox]$   

相关内容