如何使用正则表达式匹配来获取span标记元素 [英] How to get span tag elements with regex expression matching..

查看:1164
本文介绍了如何使用正则表达式匹配来获取span标记元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html o / p ..现在我需要找到一个span标签,并且我需要在span标签中获取子元素...

这里是我的代码

I have an html o/p..now i need to find a span tag and ..i need to get child elements in span tag...
here is my code

   List<string> pages = new List<string>();
            String regex = "<span class=\"prime-message\"> $1 </span>";
            MatchCollection th = Regex.Matches(data, regex, RegexOptions.Singleline);
            foreach (Match i in th)
	        {
		        string target=i.Groups[0].Value;
                target=target.Replace("<span>",string.Empty);
                target=target.Replace("</span>",string.Empty);
.
.
.
.
.



这里我无法在foreach循环中获取i一侧的span元素标签...而且我也没有得到任何元素...我怎么做到这一点...我只需要在foreach循环中的i一侧获得垃圾邮件标签....我感谢任何sugestions和建议......


here i could not getting span elements tags in side of "i" in foreach loop...and also i was not getting any elements in "th"...how coud i achieve this...i just need to get spam tag in side of "i" in foreach loop....i wasso thankfull for any sugestions and advices...

推荐答案

1< / span>;
MatchCollection th = Regex.Matches(data,regex,RegexOptions.Singleline);
foreach(匹配i)
{
string target = i.Groups [0] .Value;
target = target.Replace(< span>,string.Empty);
target = target .Replace(< / span>,string.Empty);




1 </span>"; MatchCollection th = Regex.Matches(data, regex, RegexOptions.Singleline); foreach (Match i in th) { string target=i.Groups[0].Value; target=target.Replace("<span>",string.Empty); target=target.Replace("</span>",string.Empty); . . . . .



这里我无法在foreach循环中获得i一侧的span元素标签...而且我也没有得到th中的任何元素...我怎么做到这一点......我只需要在foreach循环中的i一侧获取垃圾邮件标签....我感谢谢谢y sugestions and advices ...


here i could not getting span elements tags in side of "i" in foreach loop...and also i was not getting any elements in "th"...how coud i achieve this...i just need to get spam tag in side of "i" in foreach loop....i wasso thankfull for any sugestions and advices...


我建​​议你阅读: http: //www.regular-expressions.info/examples.html [ ^ ]

如果您想通过多行处理,请使用 MultiLine 选项而不是 SingleLine



I'd suggest to read this: http://www.regular-expressions.info/examples.html[^]
If you want to proccess through several lines, use MultiLine option instead of SingleLine.

string to search within: "<span class="\"prime-message\"">


1< / span>
pattern = < span \b [^> ] *>(。*?)< / span>
返回值:
1 </span>" pattern = "<span\b[^>]*>(.*?)</span>" returned value:


这篇关于如何使用正则表达式匹配来获取span标记元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆