如何在没有换行仍然在全局捕获的字符串中停止regex捕获?

时间:2022-04-26 14:26:42

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

我试图从一个没有换行的长字符串中提取mustache模板键。我现在:

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

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

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

它通过每个键的结束}来匹配*all字符,直到找到}的最后出现

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

如何让它捕获每个键并在全局上移动?

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

这里有一个regex101链接:http://regex101.com/r/fU0iI6/1

Thanks

谢谢

1 个解决方案

#1


3  

Make it non-greedy regex:

让它贪婪的正则表达式:

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

Regex Demo

Regex演示

#1


3  

Make it non-greedy regex:

让它贪婪的正则表达式:

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

Regex Demo

Regex演示