Regular Expression - Need a simple pattern!

  • Thread starter Thread starter mehdi
  • Start date Start date
M

mehdi

Hi,
Consider the following string:

<div>whatever text goes here, and maybe it
contains a carriage return and/or line feed
and it spans in multiple lines</div>

How am I supposed to write an expression that returns the div's
content?


Any help would be highly appreciated,

TIA,
Mehdi
 
You can't, specifically. For example, the following will capture your
example:

(?s)<div>.*</div>

However, a div may contain nested elements, and if any of them is a div, it
will capture only the outermost div, as in:

<div>whatever text goes here, and maybe it
contains a carriage return and/or line feed
<div>whatever text goes here, and maybe it
contains a carriage return and/or line feed
and it spans in multiple lines</div>
and it spans in multiple lines</div>

So, you can't do this with a regular expression alone.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Back
Top