Bug 13051

Summary: sed: the substitute command ignores the g flag if the supplied pattern starts with '^'
Product: Busybox Reporter: yvt <i>
Component: Standard ComplianceAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.33.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description yvt 2020-07-01 04:03:23 UTC
$ sed --help
BusyBox v1.31.1 () multi-call binary.
[...]

The commit <https://git.busybox.net/busybox/commit/?id=f36635cec6da728fe06b849089ce2f6c1690dc67> introduced this behavior to address the bug with `echo "aah" | sed 's/^a/b/g'`. However, this breaks other regexs, such as:

$ echo 'a b c' | sed -E 's/^a|b|c/d/g'
d b c

Simply reordering the clauses so that '^' doesn't appear at the start makes it working as intended:

$ echo 'a b c' | sed -E 's/b|^a|c/d/g'
d d d
Comment 1 Al Mr 2021-07-19 19:44:18 UTC
I'm still seeing this in 1.33.1 and master. However, removing the (updated version of) the commit mentioned by the OP does not fix

echo 'a b c' | sed -E 's/^a|b|c/d/g'

... but neither does it break `echo "aah" | sed 's/^a/b/g'`