Post History
I am trying to greedily capture text with sed. For example, I have the string abbbc, and I want to capture all of the repeated b characters, so that my result is bbb. Here's an attempt at a solut...
#1: Initial revision
greedy capture with sed
I am trying to greedily capture text with `sed`. For example, I have the string `abbbc`, and I want to capture all of the repeated `b` characters, so that my result is `bbb`. Here's an attempt at a solution: ```console $ sed -n 's/.*\(b\+\).*/\1/p' <<< abbbc b ``` As shown in the output of the command, the capture only obtains a single `b` rather than my desired result `bbb`. I know I could prepend and append the "not b" pattern (`[^b]`) to my capture, which would give me the desired result: ```console $ sed -n 's/.*[^b]\(b\+\)[^b].*/\1/p' <<< abbbc bbb ``` However, this solution is a bit inelegant, and may become much more complicated when the match is not as simple. So I'm hoping there's another way to force the capture to be greedy.
