正则表达式替换c#中的特定单词

时间:2016-08-13 05:11:26

标签: c# regex

我有一个字符串,如“请.... {@@ url}某事{@@ test} somethinng ... some {@@ url} ....”,想要完全替换字符串{@ @url}和{@@ test}通过c#

中的正则表达式

请帮助我获得正则表达式

提前致谢!

1 个答案:

答案 0 :(得分:1)

Regex to get string between curly braces "{I want what's between the curly braces}"

https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx

类似

string pattern = @"/{(.*?)}/";
string input = "Please .... {@@url} something{@@test}somethinng ... some{@@url} ....";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(input);
if (matches.Count > 0)
{
  Console.WriteLine("{0} ({1} matches):", input, matches.Count);
  foreach (Match match in matches)
     input = input.replace(match.value, "");
}