我正在尝试使用带有正则表达式模式的egrep来匹配空白。
我之前将RegEx与Perl和C#一起使用,它们都支持\s
模式来搜索空白。 egrep(或至少我使用的版本)似乎不支持此模式。
在网上的几篇文章中,我遇到了一个速记[[:space:]],但这似乎不起作用。任何帮助表示赞赏。
使用:SunOS 5.10
最佳答案
我在SunOS 5.10上看到了相同的问题。 /usr/bin/egrep
不支持扩展的正则表达式。
尝试使用/usr/xpg4/bin/egrep
:
$ echo 'this line has whitespace
thislinedoesnthave' | /usr/xpg4/bin/egrep '[[:space:]]'
this line has whitespace
另一个选择可能是只使用perl:
$ echo 'this line has whitespace
thislinedoesnthave' | perl -ne 'chomp;print "$_\n" if /[[:space:]]/'
this line has whitespace
关于regex - egrep搜索空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/448997/