Subject: bug#36148: inconsistent behaviour with anchored regex containing back-references

From: [email-masked]
Date: Sun, 9 Jun 2019 10:00:24 +0200

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)