Regex for mustache-style double braces?

前端 未结 5 990
后悔当初
后悔当初 2020-12-24 06:51

I\'m using Mustache-style tags inside of AngularJS. What\'s the best regex to use to return an array of just the text inside the mustache braces?

Sample dat

5条回答
  •  爱一瞬间的悲伤
    2020-12-24 07:26

    Something like this

    /{{\s?([^}]*)\s?}}/
    

    The values would be in first group (you know, not the 0-group, the 1-group :))

    One more point - this regex is captures everything between {{ and }}, so all the punctuation marks, braces, dots, etc. If you need only words (possibly separated by underscore or whitespace) this would be more useful for you:

    /{{\s?[\w\s]*\s?}}/
    

提交回复
热议问题