Extract Content from Div Tag C# RegEx
I need to extract this content inside the divtestimonial1 div I am using the following regEx, but its only returning the first line
Regex r = new Regex("<div([^<]*<(?!/div>))");
<div class="开发者_如何学运维testimonial_content" id="divtestimonial1"> <a name="T1"></a> <div class="testimonial_headline">%testimonial1headline</div> <p align="left"><img src="" alt="" width="193" height="204" align="left" hspace="10" id="img_T1"/><span class="testimonial_text">%testimonial1text</span><br /> </p> </div>
Regular expressions are generally not a good choice for parsing HTML. You might be better off using a tool such as HTML Agility Pack, so I would suggest you use that.
That being said, you can match your particular sample input using this Regex:
<div.*?id="divtestimonial1".*?>.*</div>
But it might break in your real-world scenario. One of the troubles with Regex and HTML is properly detecting nesting of tags, etc.
精彩评论