<!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还是原来的字符串,请帮忙看一下是哪里出了问题?
<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还是原来的字符串,请帮忙看一下是哪里出了问题?
<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")忘记了
.不能匹配换行符
<!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; }
<form(.*?)>(\s|.)*?</form>,你也可以命名内容组,以方便使用。
if (match != null)
{
rS = match.Groups[1].Value; }
是得到了我想要的,只是想进一步得到<form>...</form>之中的内容,不包含form标记。
Match m = reg.Match(rs);
if (m.Success)
{
ret = m.Value;
}
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>
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();
}
string strPattern2 = @"(?<=<form[^>]*?>).*(?=<\/form>)";
Match match = Regex.Match(strInput, strPattern2);
this.txtRegexValue.Text = match.Value;