日期:2014-05-18 浏览次数:20892 次
string source = "a_word1_text1_word2_word1_text2_word2";
Regex reg = new Regex("(?<=(word1_))[.\\s\\S]*?(?=(_word2))", RegexOptions.Multiline | RegexOptions.Singleline);
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
MessageBox.Show(m.Groups["value"].Value);
}
------解决方案--------------------
第一个问题:(?is)<div\s*id='div1'>(.*)</div> 取m.Groups[1].Value就行了
第二个问题:word1_(.*?)_word2 取m.Groups[1].Value就行了
总结你两个问题就是贪婪匹配和非懒惰匹配的用法
------解决方案--------------------