我想使用正则表达式从字符串中删除一个子字符串,从左到右,这意味着我想要正确的分隔符被识别,然后删除一切,直到在左侧找到最接近的分隔符(而不是相反的方向,左右分隔符不同)。删除分隔符之间的子字符串从左到右使用正则表达式C#
一个例子:
string myInput = "This [[ should stay and [[ this sould go | this should stay ]] as well";
string myRegex = "\\[\\[(.*?)\\|";
string myOutput = Regex.Replace (myInput, myRegex,"");
我想从去除一切 “|”到第一个“[[”在左边,但正则表达式从第一个“[[”在句子中直到“|”)。
I get: myOutput = "This this should stay ]] as well"
When what I really want is: "This [[ should stay and this should stay ]] "
非常感谢!