Update 5/26/2020
It seemed like this was a bug, so I filed a bug. Its ID is #41558.
I was just messing around with sed and I came up with this exercise: to replace the 3rd-to-last occurrence of "and" (the word, not as a substring), to create:
dog XYZ foo and bar and baz land good
I thought this would work
echo 'dog and foo and bar and baz land good' |
sed -E 's/(.*)\band\b((.*\band\b){2})/\1XYZ\2/'
but it actually replaces the 2nd-to-last occurrence of "and". The only explanation I can think of is that it's including "land" as one of the \band\b, but that shouldn't be the case because I included the \b word boundaries?
[[:<:]]and[[:>:]]instead of\band\becho lala | grep -Eo '(\bla){2}'=>lala. As a workaround, use\<and\>instead of\b.\bor the\<and\>pair