How to make simple Regex for this code?

Dear Pals,

Need your help to make a simple regex to grab all codes from <!-- Begin Code –> until <!-- End Code –>

<!-- Begin Code -->
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: '132829708015487', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>


	
		
		
		
	
				


<ul id="socialTools">
<li class="twitter">

<script type="text/javascript">
tweetmeme_style = 'compact';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
</li>
<li class="digg">

<script type="text/javascript">
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
})();
</script>
<a href="http://digg.com/></a>
</li>
<li class="buzz">

<span>
<a title="Post on Google Buzz" class="google-buzz-button"></a>
<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script>
</span>
</li>
<li class="facebook">

<fb:like href="" />
</li>
</ul>

<div style="clear: both;"></div>
<!-- End Code -->

Thanks for your kind help.


<?php
preg_match("/-->(.*)<!--/s", $subject, $matches);
echo $matches[1];

Thanks for your kind help but this regex not running in my Yahoo Pipes.

there might be another <!-- inside the first…

Can you give an example.? Thanks

There could be html comments in between the begin and end html comments that you are using to denote your search area.

Because your search is so very specific I think you can modify the above code a bit and get your desired result. When I was testing this functionality I copied your html code into a file called subject.html and read it in through the following php:

<?php
    $subject_file_handle = fopen("subject.html","r");
    
    //if the file handle is valid
    if ($subject_file_handle) {
        $subject_file_contents = "";
        //read in the file one line at a time
        while (($buffer = fgets($subject_file_handle, 4096)) !== false) {
            $subject_file_contents .= $buffer;
        }
        
        //close the file
        fclose($subject_file_handle);
    }
    
    preg_match("/<!-- Begin Code -->(.*)<!-- End Code -->/s", $subject_file_contents, $matches);

    echo $matches[1];
?>

This works even if there are html comments in the part you are trying to capture.