(.*) <div> (.*) <\/div> (.*) 
我想用这个正则表示下面的1111   可是是错的     正确的应该怎么写啊 
0000 <div> 1111 </div> 2222 <div> 3333 </div> 4444 

解决方案 »

  1.   

    string test = "0000   <div>   1111   </div>   2222   <div>   3333   </div>   4444";
    Match m = Regex.Match(test, @"(?<=<div>\s*)[\s\S]*?(?=\s*</div>)", RegexOptions.IgnoreCase);
    if (m.Success)
        MessageBox.Show(m.Value);
      

  2.   

    //<div[^>]*>(?<content>[^<]*)</div>
    string test = "0000   <div>   1111   </div>   2222   <div>   3333   </div>   4444";
    Regex reg = new Regex("<div[^>]*>(?<content>[^<]*)</div>", RegexOptions.IgnoreCase);
    Match m = Regex.Match(test);
    if (m.Success)
    string returnValue = m.Groups["content"].Value;
    //手写的没测试
      

  3.   

    string returnValue;
    string test = "0000   <div>   1111   </div>   2222   <div>   3333   </div>   4444";
    Regex reg = new Regex("<div[^>]*>(?<content>[^<]*)</div>", RegexOptions.IgnoreCase);
    Match m = Regex.Match(test);
    if (m.Success)
    returnValue = m.Groups["content"].Value;
      

  4.   

    只需要用非贪婪匹配div包含的内容就行了。<script>
    str="0000   <div>   1111   </div>   2222   <div>   3333   </div>   4444   "
    reg=/<div>(.*?)<\/div>/
    alert( str.match(reg)[1] )
    </script>
      

  5.   

    一个问题发了n个帖子。n>=4