Using Regex.Replace to keep characters that can be vary

后端 未结 3 1850
不知归路
不知归路 2021-01-06 12:29

I have the following:

string text = \"version=\\\"1,0\\\"\";

I want to replace the comma for a dot, while keeping

3条回答
  •  没有蜡笔的小新
    2021-01-06 13:00

    You need a regex like this to locate the comma

    Regex reg = new Regex("(version=\"[0-9]),([0-9]\")");
    

    Then do the repacement:

    text = reg.Replace(text, "$1.$2");
    

    You can use $1, $2, etc. to refer to the matching groups in order.

提交回复
热议问题