I am developing a plugin for Kirby CMS. It has a data type called kirby tags. I want to parse it.
I have the following input:
(link: http://google.com/ nospace:yes text: hello world foo: tesat: baz)
From which I extract:
link: http://google.com/ nospace:yes text: hello world foo: tesat: baz
Then, I need to parse this input and get the following output:
array (
'link' => 'http://google.com/',
'nospace' => 'yes',
'text' => 'hello world',
'foo' => '',
'tesat' => 'baz',
)
I almost have the desired result, but I have trouble with handling empty pairs and values with whitespace. Check my regex here:
([a-z0-9_-]+):(?:\s?(\S+))?
Basically, I need to match the start of the string or some whitespace, then some characters (the key), a colon, and all the rest, until I reach another whitespace + characters combination.
Is there a way to make it work?