Sort by

recency

|

88 Discussions

|

  • + 0 comments

    Since the grep in this environment doesn't support Perl-style regular expressions, you can't use "\d". If you use Basic Regular Expressions (the default and equivalent to --basic-regexp or -G), you can use the character class [0-9] (see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html).

    In BRE, the capture group must be defined in a subexpression with \( \) and then can be recalled with \1 (see https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions). Finally, BRE doesn't support using the precise '?' matching operator to pick out the optional space, but it does permit the more greedy '*'. So you end up with:

    grep '\([0-9]\)\s*\1'

  • + 0 comments
     grep '\(\d\)\s*\1'   
    

    there could be zero or one space between the repeated numbers...

  • + 0 comments

    I don't know why 9999 5628 9201 1232 shouldn't be in the output. I guess the test has some part wrong.

  • + 1 comment
    grep "\([0-9]\) \?\1"
    

    On my system (Ubuntu 20.04 with GNU grep 3.4 the following simpler command works as well: grep -E "([0-9]) ?\1" I don't understand why it doesn't work here.

  • + 0 comments
    grep "\(\d\)\s?\1"