Jump to content


Photo

Selecting between 2 delimiters


  • Please log in to reply
1 reply to this topic

#1 Shanti

Shanti
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 29 August 2006 - 12:40 AM

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
<!-- Start Code -->[\+;\|\=\:\-\!\.\<\,\>\\\'\"\/\w\s]+<!-- End Code -->
but this will make 1 match including everything out of those delimiters  :-\

any ideas?

Thanks

Shanti Castillo G.







#2 rea|and

rea|and
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 30 August 2006 - 11:49 AM

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:
/<!-- Start Code -->(.*?)<!-- End Code -->/s

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users