我有类似的字符串值A, something happened [1], something else [2], whatever [3]并想将其替换为A, something happened {0}, something else {1}, whatever {2}.
因此,如果之间有一个数字,则基本上[用{和]替换},然后将之间的数字减一。正则表达式可以以某种方式实现吗?
到目前为止,我得到了这个:
var text = "A, something happened [1], something else [2], whatever [3]";
var result = Regex.Replace(text, @"\[(\d+)\]", @"{$1}");
Console.Write(result);
但是,这给了我A, something happened {1}, something else {2}, whatever {3}.
有没有将数字减一的选项?
白板的微信
相关分类