sed: "repetition-operator operand invalid" using capturing groups

sed

Solution

the problems of your sed are:

- you didn't use `-r`, so sed won't use extended regex

- `\d`, `{5}` won't be recognized by sed, `\{` is not valid either because it is not closed

(without `-r`, you could use `\{5\}`; with `-r`, you could `{5}`)

this line should give you the expected output:

 sed 's/"[0-9]*":{/{/g' file

Problem

Standard regex I have a (partial) JSON string like so: ``` "99887":{"foo":"99887","bar":"paul"},"88776":{"foo":"88776"... ``` I need to get rid off the number string before each `{` to produce this: ``` {"foo":"99887","bar":"paul"},{"foo":"88776"... ``` For plain regex I'd use the pattern `("\d{5}"\:)(\{)` and keep `$2`. sed I'm having difficulties turning this into a sed command: ``` sed 's/\("\d{5}":\)\(\{\)/\2/g' ``` produces the error message error: repetition-operator operand invalid In other contexts this messages seems to relate to the fact that `sed` does not support look-ahead/behind (which I don't use).

Original source