$re = '/(struct\s*\w+.*?(?=fn))(fn.*?(?=\),)\)).*?(?=fn)(fn.*?\))(?=\R\))/s';
$str = 'struct mbuh
(
lineshg = 0,
tres = "text",
fn track all:#() =
(
local c -- clone
local lpoint = [0,0,0] -- previous point created
local ccoll = #() -- array for created objects
local prev = [0,0] -- var for alt distance changing
),
fn listzfun trs:123 x:#() =
(
obj = snapshotasmesh a
min_vz = max_vz = in coordsys world (getvert obj 1).z
min_vx = max_vx = in coordsys world (getvert obj 1).x
min_vy = max_vy = in coordsys world (getvert obj 1).y
)
)
struct mbuh
(
lineshg = 0,
tres = "text",
fn track all:#() =
(
local c -- clone
local lpoint = [0,0,0] -- previous point created
local ccoll = #() -- array for created objects
local prev = [0,0] -- var for alt distance changing
),
fn listzfun trs:123 x:#() =
(
obj = snapshotasmesh a
min_vz = max_vz = in coordsys world (getvert obj 1).z
min_vx = max_vx = in coordsys world (getvert obj 1).x
min_vy = max_vy = in coordsys world (getvert obj 1).y
)
)
fn brung man: =
(
)';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php