简体   繁体   English

正则表达式 - 用双引号和逗号替换单词之间的一部分字符串

[英]Regex - Replace a part of string between a word in double quotes and comma

I wanted to replace a part of string between a text in double quotes and comma using Regex.我想使用正则表达式替换双引号和逗号文本之间的一部分字符串。 Suppose I have a string like :假设我有一个像这样的字符串:

{Name: {\\"before\\":'Aj', \\"after\\":'Ajay'} }

So I want to extract text between "before" : and comma.所以我想提取"before" :和逗号之间的文本。 ie Aj and replace it with "Aj" .Aj并将其替换为"Aj" and same way for after text to get 'Ajay and replace it with "Ajay" .after text 获取'Ajay并将其替换为"Ajay"

Can anyone please help me on this using Regex?任何人都可以使用正则表达式帮助我吗?

how about replacing ' width "如何有关更换'宽度"

string yourString = "{Name: {\"before\":'Aj', \"after\":'Ajay'} }";
yourString = yourString.Replace('\'', '"');

//result would be: {Name: {"before":"Aj", "after":"Ajay"} }

I don't know much about regex, but I hope this works.我对正则表达式了解不多,但我希望这有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM