title: How do I extract specific text with regex
body: <p>Here is the code that I used to apply regex on the input string to extract 2 groups, namely percentage and color.</p>
  
  <pre><code>    var variable = "#clasemedia[ percentage &lt;= 100] { polygon-fill: #B20026;} #clasemedia [ percentage &lt;= 74] { polygon-fill: #DE181D; } #clasemedia [ percentage &lt;= 66] { polygon-fill: #EF3323; }#clasemedia [ percentage &lt;= 60] { polygon-fill: #FC532B; }#clasemedia [ percentage &lt;= 55] { polygon-fill: #FD7636; }#clasemedia [ percentage &lt;= 50] { polygon-fill: #FD9740; }#clasemedia [ percentage &lt;= 47] { polygon-fill: #FEAD4A; }#clasemedia [ percentage &lt;= 45] { polygon-fill: #FEC25D; }#clasemedia [ percentage &lt;= 41] { polygon-fill: #FEDA77; }#clasemedia [ percentage &lt;= 36] { polygon-fill: #FFF9A9; }"
      pollo = variable.match(/(#\w+\s*\[\s+(\w+\s+\&lt;\=\s+\w+)\]\s+\{[\s+\w-\w\:#\w;]+\})/g)
      for(i=0; i&lt;pollo.length; i++){
          promedio = pollo[i].match(/\[\s+(\w+\s+\&lt;\=\s+\d[0-9]+)\]\s/g)
          color = pollo[i].match(/\{[\s+\w-\w\:\s+#\w\s+;]+\}/g)
          $("ul").append("&lt;li&gt;percentage  "+promedio+"color "+color+"&lt;/li&gt;");
  
  }
  </code></pre>
  
  <h3>The output of the aforementioned code is the following:</h3>
  
  <pre><code>percentage [ percentage &lt;= 100] color { polygon-fill: #B20026;}
  percentage [ percentage &lt;= 74] color { polygon-fill: #DE181D; }
  </code></pre>
  
  <h3>Desired Output:</h3>
  
  <pre><code> percentage 100 color  #B20026
  </code></pre>
  
  <p>JS Fiddle - <a href="http://jsfiddle.net/QR8yB/12/" rel="nofollow">http://jsfiddle.net/QR8yB/12/</a></p>