Below I'm issuing the regular expression
(a\b) \1 to
grep and inserting a couple of test strings through stdin.
$ grep -E '(a\b) \1' a a a a a ab a ab
The parts in bold mean that there was a match. The second one,
a ab, stumps me. The capturing group can be described in words as "the character
a followed by a word boundary".
When processing the string
a ab, the regex engine matches the character
a, see that it is followed by something which isn't a "word character" and thus matches
\b. Then it matches a space. So far so good.
But then, it should be checking if
ab, and as far as I can tell it shouldn't, because following
ab we have a word character. I don't understand what's going on!
After accepting an answer, I realized I actually still don't understand what's going on. Building up from the examples above:
$ cat tests
$ grep -E '(\ba\b) \1' tests
This is telling me that the capture group includes everything except word boundaries at the right edge of the string, which I still don't understand.