<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
无标题页
</title></head>
<body>
<form name="form1" method="post" action="left.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJLTM2MjEzOTcxZGQSc/pnM0H7hCweWzr+7ESfLCEn+g==" /><table width="203" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="656"><table width="203" border="0" cellpadding="0" cellspacing="0">
  <tr>
</table>
</form>
</body>
</html>
string rS = "";string s = 上页的字符串;
rS = Regex.Replace(s, @"<form[^>]*>.*?</form>", "$1", RegexOptions.IgnoreCase);
return rS;============================================================
想取得<form></form>中间的字符串,可以还rS还是原来的字符串,请帮忙看一下是哪里出了问题?

解决方案 »

  1.   

    WebBrowser.DocumentText="<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1"> <title> 
    无标题页 
    </title> </head> 
    <body> 
    <form name="form1" method="post" action="left.aspx" id="form1"> 
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJLTM2MjEzOTcxZGQSc/pnM0H7hCweWzr+7ESfLCEn+g==" /> <table width="203" border="0" cellpadding="0" cellspacing="0"> 
      <tr> 
        <td width="656"> <table width="203" border="0" cellpadding="0" cellspacing="0"> 
      <tr> 
    </table> 
    </form> 
    </body> 
    </html> ";
    WebBrowser.GetElementByTag("form")忘记了
      

  2.   

    Regex.Replace(s, @" <form[^>]*>.*? </form>", "$1", RegexOptions.IgnoreCase); 
    .不能匹配换行符
      

  3.   

            rs = Regex.Match(rs, @"<form[^>]*>(.*)</form>", RegexOptions.Singleline).Groups[1].Value;
      

  4.   

            rs = Regex.Match(rs, @"<form[^>]*>(.*)</form>", RegexOptions.Singleline | RegexOptions.IgnoreCase).Groups[1].Value;
      

  5.   

    替换是把<form </form>以及之间的替换掉,而不是返回之间的Regex.Replace(rS, @"<form[^>]*>.*</form>", "$1", RegexOptions.Singleline);结果如下:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1"> <title> 
    无标题页 
    </title> </head> 
    <body> 
    $1
    </body> 
    </html> 如果要得到之间的内容,可以这样:
                Match match = Regex.Match(rS, @"<form[^>]*>(.*)</form>", RegexOptions.Singleline);
                if (match != null)
                {
                    rS = match.Groups[1].Value;            }
      

  6.   

    你把自己框死了,要取得form中间的内容么:
    <form(.*?)>(\s|.)*?</form>,你也可以命名内容组,以方便使用。
      

  7.   

    to CPIO:嗯,Match match = Regex.Match(rS, @" <form[^>]*>(.*) </form>", RegexOptions.Singleline); 
                if (match != null) 
                { 
                    rS = match.Groups[1].Value;             }
    是得到了我想要的,只是想进一步得到<form>...</form>之中的内容,不包含form标记。
      

  8.   

    哦,好了,我可以自定义一个html隐藏标记来截取,谢谢各位。我明天结分。
      

  9.   

     Regex reg = new Regex(@"<form\s*[^>]*\s*>(\s|.)*</form>", RegexOptions.IgnoreCase);
               Match m = reg.Match(rs);
               if (m.Success)
               {
                   ret = m.Value;
               }
      

  10.   

    其实我觉得form中间加个div,用div的innerHTML属性取更好
      

  11.   


    C# codeRegex reg=newRegex(@"(?<=(<form[^>]*>))(\n|.)*(?=</form>)", RegexOptions.IgnoreCase);
               Match m=reg.Match(rs);if(m.Success)
               {
                   ret=m.Value;
               }结果<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJLTM2MjEzOTcxZGQSc/pnM0H7hCweWzr+7ESfLCEn+g==" /><table width="203" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="656"> <table width="203" border="0" cellpadding="0" cellspacing="0">
      <tr>
    </table>
      

  12.   


    Regex reg=new Regex(@"<form(.*?)>(?<value>(\s|.)*?)</form>",RegexOptions.IgnoreCase); 
    Match m=reg.Match(rs);
    if(m.Success) 

      string ret=m.Groups["value"].value.Trim(); 

      

  13.   

     this.txtRegex.Text = "fg<form> Own future depend on itself </form> ";          
                string strPattern2 = @"(?<=<form[^>]*?>).*(?=<\/form>)";
                Match match = Regex.Match(strInput, strPattern2);
                this.txtRegexValue.Text = match.Value;