private function getDelimiterPos($string, $offset = 0, $delimiter = ';', $skipInBrackets = false)
    {
        $stack = [];
        $rbs = '\\\\';    //reg - escaped backslash
        $regPrefix = "(?<!$rbs)(?:$rbs{2})*";
        $reg = $regPrefix . '("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|';

        if ($skipInBrackets) {
            $reg .= '(\(|\))|';
        } else {
            $reg .= '()';
        }

        $reg .= '(' . preg_quote($delimiter) . ')';

        while (preg_match('%' . $reg . '%', $string, $m, PREG_OFFSET_CAPTURE, $offset)) {
            $offset = $m[0][1] + strlen($m[0][0]);
            if (end($stack) == '/*') {
                if (!empty($m[3][0])) {
                    array_pop($stack);
                }
                continue;//here we could also simplify regexp
            }
            if (end($stack) == '-- ') {
                if (!empty($m[5][0])) {
                    array_pop($stack);
                }
                continue;//here we could also simplify regexp
            }

            if (!empty($m[7][0]))// ';' found
            {
                if (empty($stack)) {
                    return $m[7][1];
                } else {
                    //var_dump($stack, substr($string, $offset-strlen($m[0][0])));
                }
            }
            if (!empty($m[6][0]))// '(' or ')' found
            {
                if (empty($stack) && $m[6][0] == '(') {
                    array_push($stack, $m[6][0]);
                } elseif ($m[6][0] == ')' && end($stack) == '(') {
                    array_pop($stack);
                }
            } elseif (!empty($m[1][0]))// ' or " found
            {
                if (end($stack) == $m[1][0]) {
                    array_pop($stack);
                } else {
                    array_push($stack, $m[1][0]);
                }
            } elseif (!empty($m[2][0])) // opening comment / *
            {
                array_push($stack, $m[2][0]);
            } elseif (!empty($m[4][0])) // opening comment --
            {
                array_push($stack, $m[4][0]);
            }
        }

        return false;
    }