Test/match string starting/ending/containing using regex or filter operators

Hi everyone!

Quite new in Ghost theme development, I am facing a problem which I cannot fin a way to solve.
I want to test a string against either a regex or using filter operators ~^, ~, or ~$ to check if it contains, starts or ends with a specific string.

For now, I cannot find a way and my only workaround is to match on the entire string but it prevents me from changing the string in the Ghost back office

    <ul class="nav">
        {{#foreach navigation}}
            {{!-- Attibutes label, url, current, slug --}}
            <li class="nav-{{slug}}{{#if current}} nav-current{{/if}}"><a href="{{url absolute="true"}}">{{label}}</a></li>
            {{#match label "Veggies[has_child]"}}
                {{#get "tags" filter="slug:~^'veggies" limit="4"}}
                    {{#foreach tags}}
                        <li class="nav-{{slug}}"><a href="{{url}}">{{name}}[subitem]</a></li>
                    {{/foreach}}
                {{/get}}
            {{/match}}
            {{#match label "Water[has_child]"}}
                {{#get "tags" filter="slug:~^'water'" limit="4"}}
                    {{#foreach tags}}
                        <li class="nav-{{slug}}"><a href="{{url}}">{{name}}[subitem]</a></li>
                    {{/foreach}}
                {{/get}}
            {{/match}}
        {{/foreach}}
    </ul>
</div>

Is there a way to achieve this string comparison using either a if or a match ?

Thanks a lot in advance and thanks to all the Ghost team! The product is awesome!

The match helper works with equality and other operators like >, but it doesn’t have the capability to do regex matching.

Ok thanks for your answer @RyanF

How would you do what I am trying to achieve?
Is there a better way than my workaround?

Can you share more about what your end goal is with this nav menu?

Yes of course !

My goal was to have a customizable nav menu with sub menu

Based on this answer: Dropdown menu for main nav - #5 by denvergeeks
I decided to create a naming convention for my tags like : activity-bike, activity-trail, activity-swim, etc.

And from the Ghost back office I wanted to be able to create a nav called Activities[activities] and the theme would know it has to fetch tags starting with the word between brackets.
Simple dev but cannot find a way to match on the label…

Your best bet here would be to create this manually. It’s a pain to do, but it’ll get the job done.

Alternatively, you could use client-side JS to populate the menu, using the Content API.

Yes that’s what I did in the end but it is “theme dependent” and cannot be customized without modifying the code…
But my case is very very specific, I just hoped there was a way to use filters operators in match