62,074
社区成员
发帖
与我相关
我的任务
分享
string source = "<p class=\"des\">111 <p> wrwrwrwrwrwrwrwrwrwerwerwer <p class=\"des\">222 <p> ";
string regex = "(<p\\s*class=\"des\"[^>]*?>)[^<]+?(<p>)";
string result = System.Text.RegularExpressions.Regex.Replace(source, regex, "$1newstring$2");
Response.Write(result);
string pageHtml = @"asdfasd<p id=""pId"" class=""des"">111 <p>dasfs";
Regex reg = new Regex(@"<p.*?class=""des"">([^>]+)<p>");
MatchCollection mc = reg.Matches(pageHtml);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups[1].ToString());
}
(?<=<p class="des"[^>]*>)[^<]*
string source = "<p class=\"des\">111 <p> wrwrwrwrwrwrwrwrwrwerwerwer <p class=\"des\">222 <p> ";
string regex = "(<p[^>]+?>)[^<]+?(<p>)";
string result = System.Text.RegularExpressions.Regex.Replace(source, regex, "$1newstring$2");
<html>
<head>
<title>Untitled Page</title>
</head>
<script>
function ttt()
{
alert(document.getElementById('pId').outerText);
//document.getElementById('pId').textContent;//firefox中用textContent
}
</script>
<body>
<form id="form1" runat="server">
<p id="pId" name = "aa" class="des">111 </p>
<a href="#" onclick="ttt()">aaaaa</a>
</form>
</body>
</html>
(?<=<p[^>]*>)[^<]*