Jump to content

Archived

This topic is now archived and is closed to further replies.

Shanti

Selecting between 2 delimiters

Recommended Posts

Hello, lets say I got this HTML File:

<!-- Start Code -->
some html here
with
lots
of diferent chars < , > \ / etc etc
<!-- End Code -->

some other stuff here more html

<!-- Start Code -->
some html here
with
lots
of diferent chars < , > \ / etc etc
<!-- End Code -->

how do i make it so that I can match anything between <!-- Start Code --> and <!-- End Code --> in the whole html file? this example should give me 2 matches

its driving me nuts been trying for a couple days with no succes, this is what i have
[code]<!-- Start Code -->[\+;\|\=\:\-\!\.\<\,\>\\\'\"\/\w\s]+<!-- End Code -->[/code]
but this will make 1 match including everything out of those delimiters  :-\

any ideas?

Thanks

Shanti Castillo G.





Share this post


Link to post
Share on other sites
In this case I guess you have to use the ungreedy local modifier "?" to force the pattern to stop after the first occurrence of whatever your delimiter is. Something like:
[code]
/<!-- Start Code -->(.*?)<!-- End Code -->/s
[/code]

Use preg_match_all if you want returned each match and not only the first one.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.