簡體   English   中英

正則表達式替換C#中的特定單詞

[英]Regex replace specific words in c#

我有一個字符串,例如“ Please .... {@@ url} something {@@ test} somethinng ... some {@@ url} ....”,想要完全替換字符串{@@ url}和{@@ test}通過C#中的正則表達式

請幫助我獲得正則表達式模式

提前致謝!

正則表達式獲取大括號之間的字符串“ {我想大括號之間是什么}”

https://msdn.microsoft.com/zh-CN/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, "");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM