Jump to content

Selecting between 2 delimiters


Shanti

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.





Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.