Is \d not supported by grep's basic expressions?

前端 未结 2 1059
庸人自扰
庸人自扰 2020-12-12 18:59

This does not generate any output. How come?

$ echo \'this 1 2 3\' | grep \'\\d\\+\'

But these do:

$ echo \'this 1 2 3\' |          


        
相关标签:
2条回答
  • 2020-12-12 19:07

    Try this $ echo 'this 1 2 3' | grep '[0-9]\+'

    0 讨论(0)
  • 2020-12-12 19:23

    grep's default mode is (iirc) POSIX regex, and \d is pcre. You can either pass -P to gnu grep, for perl-like regexps, or use [[:digit:]] instead of \d.

    daenyth@Bragi ~ $ echo 1 | grep -P '\d'
    1
    daenyth@Bragi ~ $ echo 1 | grep '[[:digit:]]'
    1
    
    0 讨论(0)
提交回复
热议问题