string test=@"我想要一个替换 的 想要替换[code=c#]把这里内容有\n的 替换掉 外面的不替换只替换code里面的,怎 么写啊"; Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline); string ret = r1.Match(test).Value; ret=r1.Replace(test,new MatchEvaluator(CapText)); } static string CapText(Match m) { string x = m.ToString().Replace("\\n","(我是\\n)"); return x; }[/code]
static void Main(string[] args) { string test=@"我想要一个替换 的 想要替换[code=W#]把这里内容有\n的 替换掉[/code] 外面的不替换只替换code里面的,怎 么写啊"; Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline); string ret = r1.Match(test).Value; ret=r1.Replace(test,new MatchEvaluator(CapText)); } static string CapText(Match m) { // Get the matched string. string x = m.ToString().Replace("\\n","(我是\\n)"); // If the first char is lower case...
{
string test=@"我想要一个替换 的
想要替换[code=c#]把这里内容有\n的
替换掉
外面的不替换只替换code里面的,怎 么写啊"; Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline); string ret = r1.Match(test).Value;
ret=r1.Replace(test,new MatchEvaluator(CapText)); } static string CapText(Match m)
{
string x = m.ToString().Replace("\\n","(我是\\n)");
return x;
}[/code]
{
string test=@"我想要一个替换 的
想要替换[code=W#]把这里内容有\n的
替换掉[/code]
外面的不替换只替换code里面的,怎 么写啊"; Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline); string ret = r1.Match(test).Value;
ret=r1.Replace(test,new MatchEvaluator(CapText)); } static string CapText(Match m)
{
// Get the matched string.
string x = m.ToString().Replace("\\n","(我是\\n)");
// If the first char is lower case...
return x;
}