我有一个字符串,如“请.... {@@ url}某事{@@ test} somethinng ... some {@@ url} ....”,想要完全替换字符串{@ @url}和{@@ test}通过c#
中的正则表达式请帮助我获得正则表达式
提前致谢!
答案 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, "");
}