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>
  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 +


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

<script type="text/javascript">
tweetmeme_style = 'compact';
<script type="text/javascript" src=""></script>
<li class="digg">

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

<a title="Post on Google Buzz" class="google-buzz-button"></a>
<script type="text/javascript" src=""></script>
<li class="facebook">

<fb:like href="" />

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

Thanks for your kind help.

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:

    $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
    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.