Regex for mustache-style double braces?

前端 未结 5 996
后悔当初
后悔当初 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:07

    If you use a global search with .match, JavaScript won't give the capture groups in its array output. As such, you need to do it twice: Once to find the {{...}} pairs, then again to extract the names from within them:

    str.match(/{{\s*[\w\.]+\s*}}/g)
       .map(function(x) { return x.match(/[\w\.]+/)[0]; });
    

提交回复
热议问题