I'm working through regular expression examples at the linux command line. Specifically I'm looking at the regex '*' qualifier that refers to 'zero or more occurrences of the preceding element' It's clear in the trivial example below why 'rrr' is substituted with 'x'
[..~]$ echo rrr | sed -re 's/r*/x/g'
x
It's not clear to me what is going on in the following two examples:
[..~]$ echo f | sed -re 's/r*/x/g'
xfx
[..~]$ echo fd | sed -re 's/r*/x/g'
xfxdx
Does sed encounter the 'f' as the first element in the text stream and determines there are zero occurrences of 'r', passes the 'x' to the stdout followed by 'f'? If so, why is there then a trailing 'x'?