【发布时间】:2023-03-28 22:59:01
【问题描述】:
我正在尝试使用正则表达式从字符串中从左到右删除子字符串,这意味着我希望识别正确的分隔符,然后删除所有内容,直到在左侧找到最接近的分隔符(而不是其他方式左右分隔符不同)。
一个例子:
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 ]] "
非常感谢您的帮助!
【问题讨论】: