Non-greedy match is still too greedy

前端 未结 2 760
清歌不尽
清歌不尽 2021-01-25 06:31

I have a regex pattern that needs to capture the shortest matches, but the lazy match isn\'t working in cases where that pattern is nested. Here\'s what I mean:

Regex pa

相关标签:
2条回答
  • 2021-01-25 07:00

    Well, problem is that .* matches everything. if you want just to match content between {{ and }}, you can try following regex:

    \{{2}[^\{]*?\}{2}
    

    See demo at regex101

    0 讨论(0)
  • 2021-01-25 07:15

    Try: {{[^{]*?}} This is using the fact that the '{' character should not appear in the inner strings. It does match what you expect.

    0 讨论(0)
提交回复
热议问题