# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/(?(DEFINE)
(?<nestedBrackets> \[ [^][]* (?:\g<nestedBrackets>[^][]*)*+ ] )
)
(?: # two possible entry points
\G(?!\A) # 1. contiguous to a previous match
| # OR
[^[]* \[ # 2. all characters until an opening bracket
)
# all possible characters until "," or the closing bracket:
[^]["]* # all that is not ] [ or "
(?:
\g<nestedBrackets> [^]["]* # possible nested brackets
| # OR
"(?!,") [^]["]* # a quote not followed by ,"
)*+ # repeat as needed
\K # remove all on the left from match result
(?:
"," # match the target
|
] (*SKIP)(*F) # closing bracket: break the contiguity
)/|,|/gx;t' <<< "[word:\"pla pla\",\"pla pla\",\"[other_word:\"pla pla\",\"[word:\"pla\",\"pla\"end word]\",\"pla pla\"end other_word]\",\"pla pla\",\"[word:\"pla\",\"pla\"end word]\"end word]\",\""
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html