using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?(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
)";
string substitution = @"|,|";
string input = @"[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]"",""";
RegexOptions options = RegexOptions.IgnorePatternWhitespace;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx