title: use variable in pattern
body: <p>i am new to jquery I have a simple html textarea and I want to count specific word in text area and show that count and also highlight that text too.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
     
  
      $(".text").on('input',function(){
      var a= $(".text").val();
      //var a="i m running";
       /*if(a==="nokia"){
   
   alert("nokia found");
      }
      else{
   alert("not found");
      }*/
       var pattern = /nokia/;
      var pattern1 = /samsung/;
      var pattern2 = /iphone/;
      var pattern3 = /qmobile/;
      //returns true or false...
      var exists = pattern.test(a);
      var exists1 = pattern1.test(a);
      var exists2 = pattern2.test(a);
      var exists3 = pattern3.test(a);
      if(exists){
      //true statement, do whatever
      //alert("nokia");
      $(".nokia").css("background-color", "green"); 
       }
       else{
         //false statement..do whatever
       //alert("not nokia");
         $(".nokia").css("background-color", "red");
        }
        if(exists1){
         //true statement, do whatever
         //alert("samsung found");
         $(".samsung").css("background-color", "green");
       }
      else{
       //false statement..do whatever
       // alert("not samsung found");
        $(".samsung").css("background-color", "red");
       }
       if(exists2){
       //true statement, do whatever
      //alert("samsung found");
       $(".iphone").css("background-color", "green");
      }
       else{
       //false statement..do whatever
       //alert("not samsung found");
        $(".iphone").css("background-color", "red");
      }
      if(exists3){
       //true statement, do whatever
       // alert("samsung found");
       $(".qmobile").css("background-color", "green");
      }
      else{
       //false statement..do whatever
      //alert("not samsung found");
      $(".qmobile").css("background-color", "red");
      }
      });
        counter = function() {
        var value = $('#text').val();
  
       if (value.length == 0) {
          $('#wordCount').html(0);
          $('#totalChars').html(0);
          $('#charCount').html(0);
          $('#charCountNoSpace').html(0);
          return;
       }
        var regex = /\s+/gi;
        var wordCount = value.trim().replace(regex, ' ').split(' ').length;
      $('#wordCount').html(wordCount);
       };
       $(document).ready(function() {
      $('#text').keydown(counter);
      });
      });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;textarea  id='text' style="width: 50%;height: 20%;"  type="text" class="text"/&gt;&lt;/textarea&gt;
  &lt;button name="click" class="btn"/&gt;click&lt;/button&gt;
  &lt;div id="result"&gt;
          Words: &lt;span id="wordCount"&gt;0&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;ul&gt;
  
      &lt;li class="nokia"&gt;nokia&lt;/li&gt;
   &lt;li class="samsung"&gt;samsung&lt;/li&gt;
   &lt;li class="iphone"&gt;iphone&lt;/li&gt;
   &lt;li class="qmobile"&gt;qmobile&lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>