Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
.
.
.
.
.

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...
Posted

1 solution

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>"
returned value:          $1


Tested via: RegexDesigner[^]
 
Share this answer
 
v2
Comments
RaisKazi 22-Jul-14 11:04am    
My 5.
Maciej Los 22-Jul-14 11:08am    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900