Post History
The b\+ part of the regex is already greedy. In sed, all repetitions are greedy. Your problem is that the initial .* is also greedy, and so that's gobbling up both the a and as many bs as it can. F...
#1: Initial revision
The `b\+` part of the regex is already greedy. In sed, all repetitions are greedy. Your problem is that the initial `.*` is also greedy, and so that's gobbling up both the `a` and as many `b`s as it can. For this example, you can change that part to `[^b]*`: ``` $ sed -n 's/[^b]*\(b\+\).*/\1/p' <<< abbbc bbb ``` For more complicated situations, sed is unlikely to cut it. grep might be a more natural fit for what you're trying to do anyway. ``` $ grep -o 'b\+' <<< abbbc bbb ```