0
我有一個字符串,如「Please .... {@@ url} something {@@ test} somethinng ... some {@@ url} ....」,想要正是替換字符串{@@ URL}和C#正則表達式替換c中的特定字詞
{@@測試}通過正則表達式請幫助我獲得正則表達式模式
提前感謝!
我有一個字符串,如「Please .... {@@ url} something {@@ test} somethinng ... some {@@ url} ....」,想要正是替換字符串{@@ URL}和C#正則表達式替換c中的特定字詞
{@@測試}通過正則表達式請幫助我獲得正則表達式模式
提前感謝!
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, "");
}
感謝斯圖爾特refrences –