如何使用正则表达式匹配来获取span标记元素 [英] How to get span tag elements with regex expression matching..
问题描述
我有一个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, useMultiLine
option instead ofSingleLine
.
string to search within: "<span class="\"prime-message\"">
1< / span>
pattern = < span \b [^> ] *>(。*?)< / span>
返回值:
1 </span>" pattern = "<span\b[^>]*>(.*?)</span>" returned value:
这篇关于如何使用正则表达式匹配来获取span标记元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!