$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);
Warum ist die Ausgabe:Wie verstehst du die Ausgabe der PHP Regex, die unten passt?
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) "{"
}
Es scheint mir, dass ^([\S\s]+)
die gesamte Zeichenfolge übereinstimmen können ..
Sie haben Recht mit '[\ s \ S]'. Siehe http://stackoverflow.com/questions/4544636/what-does-ss-mean-in-regex-in-php – codaddict