正则表达式在引号C#之间替换分号

时间:2017-04-05 13:43:56

标签: c# regex

我想用空格替换引号中包含的所有分号。我怎样才能在C#

中执行此操作

例如:

这个字符串:

this is an example; "this is other ; example"

会回来:

this is an example; "this is other example"

我等待你的帮助!

3 个答案:

答案 0 :(得分:4)

试试这个:

string input = "this is an example; \"this is other ; example\"";
var regex = new Regex("\\\"(.*?)\\\"");
var output = regex.Replace(input, m => m.Value.Replace(";"," "));

答案 1 :(得分:0)

编辑:这将有效。

string yourString = "hello there; \"this should ; be replaced \"";

string fixedString = Regex.Replace(yourString, "(\"[^\",]+);([^\"]+\")", delegate (Match match)
{
    string v = match.ToString();
    return v.Replace(";", " ");
});

答案 2 :(得分:-2)

请尝试以下操作:

"images": [
    {
        "key": "value"
    },
    {
        "key": "value"
    }
]