OK, let's go over this regex:
"($this->block_start_word|$this->block_end_word)[[:blank:]]*([0-9a-zA-Z\_]+)[[:blank:]]*$this->block_end_delim(.*)"
I presume you want:
- either the literal string
$this->block_start_word
or $this->block_end_word
- followed by 0 or more blankspace characters
- followed by 1 or more alphanumeric characters
- followed by 0 or more blankspaces
- followed by the literal string
$this->block_end_delim
- until the end of the line
That in mind, how about
<?php
$handle = fopen('php://stdin', "r");
while (($line = fgets($handle, 4096)) !== false) {
$exp = '/';
$exp .= '(';
$exp .= '\$this\-\>block_start_word';
$exp .= '|';
$exp .= '\$this\-\>block_end_word';
$exp .= ')';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= '([0-9a-zA-Z\_]+)';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= '\$this\-\>block_end_delim';
$exp .= '(.*)/';
if(preg_match($exp,$line)) {
print $line;
}
}
?>
If $this->block_start_word
, $this->block_end_word
, and $this->block_end_delim
are set elsewhere in the PHP script:
<?php
$handle = fopen('php://stdin', "r");
while (($line = fgets($handle, 4096)) !== false) {
$exp = '/';
$exp .= '(';
$exp .= '$this->block_start_word;
$exp .= '|';
$exp .= '$this->block_end_word;
$exp .= ')';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= '([0-9a-zA-Z\_]+)';
$exp .= '\s*'; // Like [[:blank:]]*
$exp .= $this->block_end_delim;
$exp .= '(.*)/';
if(preg_match($exp,$line)) {
print $line;
}
}
?>