There seems to be a problem with beginning/end-of-line anchors in regex
containing back-references:

$ grep -V | head -1
grep (GNU grep) 3.1

$ cat words
ana
deed
ill
stats

Using -x to match whole line works:

$ egrep -x '(.?)(.?).?\2\1' words 
ana
deed
stats

Using explicit anchors emits false positives:

$ egrep   '^(.?)(.?).?\2\1$' words 
ana
deed
ill     <<<
stats

On the other hand, colouring the output shows that grep somewhat knows its
mistake:

$ egrep --color '^(.?)(.?).?\2\1$' words 
ana     (coloured)
deed    (coloured)
ill
stats   (coloured)




Reply via email to