We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Linux Shell
- Grep Sed Awk
- 'Grep' - B
- Discussions
'Grep' - B
'Grep' - B
Sort by
recency
|
92 Discussions
|
Please Login in order to post a comment
grep -E "([[:digit:]])[[:space:]]?\1"
this command is working on my local VM but not passing the test cases. What is the mistake here?
what a nice question!
Not sure why this works in test case0 but fails when i submut, for hidden test case: grep -E '([0-9])\1{1,}'
why doesn't this work?
nor does this:
grep '\(.\) \?\1'Since the
grepin 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-regexpor-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'