tags:

views:

60

answers:

3

Can somebody explain me why the following text:

<p>some text some text...</p>
<p>another text another <b>text</b>again</p>

can't be parsed with the following regular expression:

<p>.*?</p>

(to retrieve every paragraph). The regular expression that should match the text between the first opening <p> tag and the last closing </p> tag doesn't work either:

<p>.*</p>
+1  A: 

My first guess is that you are attempting a multi line match without telling the regex engine to do so. Take a look at the MSDN doc for passing in the flag.

rerun
I tried both - with and without the RegexOptions.Multiline option: neither works
Serge
+1  A: 

You can't parse HTML with RegEx.

Jeff Yates
A: 

Besides the fact that it's dangerous to parse (X)HTMl with regex, try with the RegexOptions.Singleline

Bart Kiers
thank you Bart K.I got the results I wanted with Singleline
Serge