C#(a.cs)
using System;
public class Test
{
public void Middle(string start, string end)
{
string pat1 = string.Format("(?<={0}).*(?={1})", start, end);
Console.WriteLine(pat1);
string pat2 = string.Format("(?<={{0}}).*(?={{1}})", start, end);
Console.WriteLine(pat2);
string pat3 = string.Format("(?<={{{0}}}).*(?={{{1}}})", start, end);
Console.WriteLine(pat3);
}
public static void Main(string[] args)
{
string start = "12";
string end = "35";
Test t = new Test();
t.Middle(start, end);
}
}
编译运行:
E:\>csc a.cs
Microsoft(R) Visual C# 2010 编译器 4.0.30319.1 版
版权所有(C) Microsoft Corporation。保留所有权利。
E:\>a.exe
(?<=12).*(?=35)
(?<={0}).*(?={1})
(?<={12}).*(?={35})
E:\>
结论: {{ 得到 { , }} 得到 }
更多信息可参考:http://msdn.microsoft.com/zh-cn/library/txafckwd.aspx