This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
The community reviewed whether to reopen this question 4 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
根据 POSIX 中的规定,
grep
使用基本正则表达式,但\d
是 Perl 兼容正则表达式的一部分(PCRE)。如果您使用 GNU grep,则可以使用
-P
选项来允许使用 PCRE 正则表达式。否则,您可以使用 POSIX 指定的[[:digit:]]
字符类来代替\d
。As specified in POSIX,
grep
uses basic regular expressions, but\d
is part of a Perl-compatible regular expression (PCRE).If you are using GNU grep, you can use the
-P
option, to allow use of PCRE regular expressions. Otherwise you can use the POSIX-specified[[:digit:]]
character class in place of\d
.试试这个
$ echo 'this 1 2 3' | grep '[0-9]\+'
Try this
$ echo 'this 1 2 3' | grep '[0-9]\+'