.* matches anything preceding sub_. Since sed is greedy, that gobbles up the "B sub_FF123456" all the way through the comment and null. The \([0-9A-Fa-f]*\) matches 0 or more times, so it captures an empty string, which via the \1 replaces the output.
The CHDK version should really use at least a \+ for the capture, but it at least explicitly looks for the B