可能重复:
How to Regex search/replace only first occurrence in a string in .NET?
如何让Regex.Replace只替换第一个找到的模式?
答案 0 :(得分:48)
Regex.Replace ( String, String, Int32 )
(MSDN)怎么样?
一个例子:
Regex rgx = new Regex(pattern);
string result = rgx.Replace(str, replacement, 1); // The 1 makes the difference
答案 1 :(得分:2)
http://msdn.microsoft.com/en-us/library/haekbhys.aspx
您可以使用Regex.Replace(input, replacement, count);