Reputation: 7187
I am building a very basic template engine. My template is super simple:
...html code before...
{{ foreach apples }}
... html code to be repeated {{apple}} ...
{{ endforeach }}
{{ foreach oranges }}
... html code to be repeated {{orange}} ...
{{ endforeach }}
...html code after ...
My goal is to get the first foreach (apples) and I've arrived here: https://regex101.com/r/cD5gY4/2
Does anybody have an idea about how I could stop to the end of the first loop instead of capturing both?
Upvotes: 0
Views: 45
Reputation: 3036
.*
is greedy, make it non-greedy by adding a quantifier like ?
to it. Try this:
{{\s*foreach ([a-z]+)\s*}}(.*?)({{\s*endforeach\s*}})
Upvotes: 1