Last active
April 5, 2016 13:07
-
-
Save tbreuss/3797c479c39abcf607f345025567db15 to your computer and use it in GitHub Desktop.
Regex to capture colon-separated key-value pairs, with multi-line values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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