Search code examples
javascriptregexmustache

How to stop a regex capture in a string with no newlines yet still capture globally?


I'm trying to extract mustache template keys from a long string with no newlines. I currently have:

\{\{[^><](.+)\}\}

Which keeps matching *all character past each key's closing }} until it it finds the last occurrence of }}

How do I get it to capture each key and move on globally?

Here's a regex101 link: http://regex101.com/r/fU0iI6/1

Thanks


Solution

  • Make it non-greedy regex:

    \{\{[^><](.+?)\}\}
    

    Regex Demo