title: detecting binding expression in string by js
body: <p>I have string that may contain any html elements , sentences , numbers etc stored in variable <strong>x</strong> now I want to find binding expression <strong>{{ }}</strong> and it's inner element in very effective way. I have program that mostly works fine  but fails sometime so I am searching very effective way to do it.</p>
  
  <pre><code>function call(x){
     var  p = 0,
          d = [],
          g = x.replace(/\s/g, '');
      for(var i = p ; i&lt; g.length; i++){
        x = x.substr(p,x.length - p);
        f1 = x.indexOf('}*');
        f2 = x.indexOf('*{');
        if(f1 == -1 || f2 == -1){
          break;
        }
        c = x.substr(f2+1,f1-f2);
        d.push(c.replace(/}|{/g,''))
        var p = f2+(c.length+2);
      }
     return d;
   }
  
  var x = `&lt;div&gt; 
            &lt;span class="*{race}*"&gt;
              *{name}*
            &lt;/span&gt;
        &lt;/div&gt;`;
  
      console.log(call(x));
  </code></pre>
  
  <p>This works fine in most of the cases but I am searching for more effective way and small idea to do this.</p>
  
  <ul>
  <li><h2>Please don't suggest idea using jquery</h2></li>
  </ul>