I have several texts with custom macro tags in it. I want to parse the content of these tags but I'd like to treat the ones with parameters in it differently.
I need to construct valid URLs out of these bracket contents.
Example:
This is my text:
{gallery}events/2016-02-18-Sunny-Sport-Day,single=IMG_0336.jpg,salign=left{/gallery}
Hey there! We had a great day with a tough but funny competition. Our team had a great race and was able to finish in second place.
{gallery}events/2016-02-18-Sunny-Sport-Day{/gallery}
{gallery}team/members{/gallery}
So I need to extract the path parts of the string between the {gallery} tags but I don't want to match those with parameters such as "single=IMG_0336.jpg,salign=left" because these are treated separately.
I need something which does the following:
{gallery}events/2016-02-18-Sunny-Sport-Day,single=IMG_0336.jpg,salign=left{/gallery}
becomes
first output: events/2016-02-18-Sunny-Sport-Day
second output: IMG_0336.jpg
and
{gallery}events/2016-02-18-Sunny-Sport-Day{/gallery}
becomes
events/2016-02-18-Sunny-Sport-Day
Tried the following regex:
/\{gallery\}(.*?)(?!single=)\{\/gallery\}/
But it allways matches the whole string including the single parameter.
To get the content of the single parameter I tried the following:
/,single=(.*?),/
This works fine for the single paramter only but I don't know how to get everything together.
Conclusion:
In a PHP environment I would like to have as output two arrays. The first consists only of the folders:
- events/2016-02-18-Sunny-Sport-Day
- team/members
and a second array which consists of the single file paths:
- events/2016-02-18-Sunny-Sport-Dayist/IMG_0336.jpg