[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

regular expression question

Boban Dragojlovic

7/17/2003 8:27:00 PM


I'm trying to write a regular expression search to find every instance of a
certain kind of tag within HTML.

For example, I might want to find every instance of the DIV tag, and get
back the "stuff in the middle"

For the search pattern, I specify ".*" for the stuff in the middle.

e.g. <DIV.*</DIV>

But since it is "greedy" it will scan until the VERY LAST </DIV> statement,
and just give me back a single match.


How do I tell it to find the first instance, as opposed to being greedy and
finding the last instance at the end?



1 Answer

Ralf Berkvens

7/18/2003 7:20:00 AM

0

Try

<DIV .*?</DIV>

the ? should make the .* ''ungreedy''.

Be careful with using this kind of regexp in JScript though.
It seems to sometimes go into an endless loop if there are \n or \r
characters in the string.

Ralf

"Boban Dragojlovic" <news@_N_O_S_P_AM_dragojlovic.org> wrote in message
news:BEDRa.1624$xG1.913@newssvr22.news.prodigy.com...
>
> I''m trying to write a regular expression search to find every instance of
a
> certain kind of tag within HTML.
>
> For example, I might want to find every instance of the DIV tag, and get
> back the "stuff in the middle"
>
> For the search pattern, I specify ".*" for the stuff in the middle.
>
> e.g. <DIV.*</DIV>
>
> But since it is "greedy" it will scan until the VERY LAST </DIV>
statement,
> and just give me back a single match.
>
>
> How do I tell it to find the first instance, as opposed to being greedy
and
> finding the last instance at the end?
>
>
>