string x = "Live for nothing,die for something";
string y = "Live for nothing,die for somebody";
Regex r = new Regex(@"^Live ([a-z]{3}) no([a-z]{5}),die \1 some\2$");
Console.WriteLine("x match count:" + r.Matches(x).Count); //1
Console.WriteLine("y match count:" + r.Matches(y).Count); //0
Console.WriteLine("-------------------------");
疑问:\1和\2分别代表着什么呀
string y = "Live for nothing,die for somebody";
Regex r = new Regex(@"^Live ([a-z]{3}) no([a-z]{5}),die \1 some\2$");
Console.WriteLine("x match count:" + r.Matches(x).Count); //1
Console.WriteLine("y match count:" + r.Matches(y).Count); //0
Console.WriteLine("-------------------------");
疑问:\1和\2分别代表着什么呀
\2 : ([a-z]{5})
带标记的表达式 :{} 第 n 个带标记的文本 \n 执行替换
Regex r = new Regex(@"^Live ([a-z]{3}) no([a-z]{5}),die \1 some\2$");
第一个 第二个 第一 第二
http://msdn.microsoft.com/zh-cn/library/2k3te2cs.aspx
第一个表达式 第二个 第一 第二
\2 : ([a-z]{5})
正则基础之——反向引用