Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#5
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 22-Jul-14 1:21am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
v2
Comments
RaisKazi at 22-Jul-14 11:04am
   
My 5.
Maciej Los at 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)

  Print Answers RSS
0 OriginalGriff 280
1 Maciej Los 280
2 BillWoodruff 240
3 Afzaal Ahmad Zeeshan 239
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 22 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100