I'm using the sd tool which uses rust regular expressions, and I am trying to use it with a named capture group, however if in the replacement the named capture group precedes a string, then the string is included as the potential the for named capture group, causing unexpected behaviour.
Here is a contrived example to illustrate the issue:
echo 'abc' | sd -p '(?P<cg>b)' '$cgB'
# outputs: ac
# desired output: abBc
echo 'abc' | sd -p '(?P<cg>b)' '$cg B'
# outputs as expected: ab Bc
# however, places a space there
I've tried $<cg>B, $cg(B), $cg\0B, all don't give abBc.
I've also checked the rust regex docs however the x flag, and other techniques seem only applicable to the search pattern, not the replace pattern.