62,046
社区成员
发帖
与我相关
我的任务
分享
C盘建一个1.txt
C# code
<div id="title" class="blog_tit_cont">
<strong>
<span >
<span>[转]</span>
为了练好口语,你敢不敢每天读一遍,坚持一个月?
</span>
</strong>
<span id="pubTime" class="c_tx3">
<script type="text/javascript">
var pubtime = g_oBlogData.data.pubtime;
var pubDate = new Date(pubtime * 1000);
document.write(pubDate.getFullYear() + "." + (pubDate.getMonth() + 1) + "." + pubDate.getDate());
</script>
</span>
<span id="readNum" class="c_tx3"> </span>
<span id="quoteInfo" class="c_tx3"> </span>
</div>
string strfromtxt = File.ReadAllText(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
List<string> pro = new List<string>();
MatchCollection matches1 = Regex.Matches(strfromtxt, @"(?is)<div\s*id=""title""\s*class=""blog_tit_cont"">\s*<strong>(?<strong>(.*))</strong>(.*?)</div>", RegexOptions.IgnoreCase);
foreach (Match match in matches1)
{
string contemp = match.Groups["strong"].Value;
pro.Add(contemp);
}
<div id="title" class="blog_tit_cont">
<strong>
<span >
<span>[转]</span>
为了练好口语,你敢不敢每天读一遍,坚持一个月?
</span>
</strong>
<span id="pubTime" class="c_tx3">
<script type="text/javascript">
var pubtime = g_oBlogData.data.pubtime;
var pubDate = new Date(pubtime * 1000);
document.write(pubDate.getFullYear() + "." + (pubDate.getMonth() + 1) + "." + pubDate.getDate());
</script>
</span>
<span id="readNum" class="c_tx3"> </span>
<span id="quoteInfo" class="c_tx3"> </span>
</div>
string strfromtxt = File.ReadAllText(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
List<string> pro = new List<string>();
MatchCollection matches1 = Regex.Matches(strfromtxt, @"(?is)<strong>(?<strong>(.*))</strong>", RegexOptions.IgnoreCase);
foreach (Match match in matches1)
{
string contemp = match.Groups["strong"].Value;
pro.Add(contemp);//结果数据
}
static void Main(string[] args)
{
string str = @"<div id=""title"" class=""blog_tit_cont"">
<strong>
<span >
<span>[转]</span>
为了练好口语,你敢不敢每天读一遍,坚持一个月?
</span>
</strong>
<span id=""pubTime"" class=""c_tx3"">
<script type=""text/javascript"">
var pubtime = g_oBlogData.data.pubtime;
var pubDate = new Date(pubtime * 1000);
document.write(pubDate.getFullYear() + ""."" + (pubDate.getMonth() + 1) + ""."" + pubDate.getDate());
</script>
</span>
<span id=""readNum"" class=""c_tx3""> </span>
<span id=""quoteInfo"" class=""c_tx3""> </span>
</div>
";
Regex re = new Regex(@"(?is)(?<=<div id=""title""[^>]+>\s*<strong>).*?(?=</strong>)", RegexOptions.None);
Console.WriteLine(re.Match(str).Value); //re.Match(str).Value就是你要的
Console.ReadLine();
}
Regex reg = new Regex(@"(?is)<div[^>]*>(?:(?!</?div).)*(<strong[^>]*>.*?</strong>)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
}