How to understand the output of the PHP regex matching below?
Posted
by
smarty
on Stack Overflow
See other posts from Stack Overflow
or by smarty
Published on 2010-12-29T07:24:08Z
Indexed on
2010/12/29
7:53 UTC
Read the original article
Hit count: 169
$file = '{include file="{$COMMON_TPL_PATH}common/header_admin.tpl"}
{include file="{$mainPage}"}
{include file="{$COMMON_TPL_PATH}common/footer_admin.tpl"}';
preg_match('/^(\{\})|^(\{\*([\S\s]*?)\*\})|^(<\?(?:php\w+|=|[a-zA-Z]+)?)|^([ ]*[
]+[ ]*)|^(\{strip\})|^(\{\/strip\})|^(\{literal\})|^(\{\s{1,}\/)|^(\{\s{1,})|^(\{\/)|^(\{)|^(([\S\s]*?)(?=([ ]*[
]+[ ]*|\{|<\?)))|^([\S\s]+)/', $file, $matches);
var_dump($matches);
Why the output is:
array(13) {
[0]=>
string(1) "{"
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(1) "{"
}
It seems to me that ^([\S\s]+)
can match the whole string..
© Stack Overflow or respective owner