Since everything else in this node is indented (if I understand YAML correctly), this works, at least in your example line:
$mask = '~(^%s:\n(?:^[ ].*\n?)*$)~m'; $pattern = sprintf($mask, 'Node2'); $r = preg_match($pattern, $yaml, $matches); $node = reset($matches);
At least on my computer. I wanted to make a demo version of the code, but this gives an error. Will check for regex.
Fully bloated:
$yaml = <<<EOD Node1: Child: GrandChild: foo Node2: AnotherChild: AnotherGrandChild: bar Node3: LastChild: LastGrandChild: foo EOD; $mask = '~ (
hakre source share