Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tbreuss/3797c479c39abcf607f345025567db15 to your computer and use it in GitHub Desktop.
Save tbreuss/3797c479c39abcf607f345025567db15 to your computer and use it in GitHub Desktop.
Regex to capture colon-separated key-value pairs, with multi-line values
<?php
$contents = "
@title: Tests / Variablen
@menu: Variablen
@layout: default.html
@format: md
@twig: 1
@date: 1388102400
@keep_extension: 0
@content_type: text/html
@authors:
- William Shakespeare
- Franz Kafka
- Charles Dickens
- Oscar Wilde
@categories:
- Belletristik
- Fachliteratur
- Ratgeber
- Sachbücher
@tags:
- Biografie
- Esoterik
- Krimi
- Kunst
@nocache: 1
@hidden: 1
@custom1: Meine Variable 1
@custom2: Meine Variable 2
@excerpt: Gibt auf dieser Seite alle globalen, site- und page-Variablen aus.
@content: Diverser Inhalt
mit Zeilenumbrüchen etc.";
preg_match_all("/@([A-Za-z_][^:]*):([^\r\n]*(?:[\r\n]+(?!@[A-Za-z_].*:).*)*)/m", $contents, $out);
print_r($out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment