TheAppService TheAppService - 1 month ago 4
PHP Question

PHP Regex get everything outside of two tags

I've got a String in the following format:

firstlayer{secondlayer;secondlayer,secondlayer};firstlayer{secondlayer;secondlayer}


I now want to exclude all values between the "{}" Tags, so that I can simply explode the String with the semicolon. -> I want to get all the first layer values.

EDIT:
My first try had been this:

preg_match_all("(.*?)~\{\}~(.*?)", $string,$match);


but it doesn't seem to work...

Answer
$str = 'firstlayer{secondlayer;secondlayer,secondlayer};firstlayer{secondlayer;secondlayer}';
if (preg_match_all('~(\w+)\{(.*?)\}~', $str, $m)) {
    print_r($m);
}

output is:

Array
(
    [0] => Array
        (
            [0] => firstlayer{secondlayer;secondlayer,secondlayer}
            [1] => firstlayer{secondlayer;secondlayer}
        )

    [1] => Array
        (
            [0] => firstlayer
            [1] => firstlayer
        )

    [2] => Array
        (
            [0] => secondlayer;secondlayer,secondlayer
            [1] => secondlayer;secondlayer
        )

)
Comments