title: How to pass a variable in match function in javascript?
body: <p>Firstly this may sound like a duplicate question but I was unable to resolve my problem using the previous asked questions:
  This is my HTML page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;script&gt;
  
      function test() {
        var totalids='XYZ@@';
        var variable_name=document.getElementById('p1').value.replace(/^\s+|\s+$/g,''); 
        var result = totalids.match(/variable_name/i);
        if (result){
          alert('Matched');
        } else {
          alert("Not Matched");
        }
      }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;input type="button" value="click on me" onclick="test()"&gt;
       &lt;input type="text" value="xyz" id="p1"&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>This program is not matching my String.I want to match my string using case-insensitive match.I know the problem lies in this line:</p>
  
  <pre><code> var result = totalids.match(/variable_name/i);
  </code></pre>
  
  <p>I am unable to pass variable in match function.I can do this;</p>
  
  <pre><code> var re = new RegExp(str1, "g");
  </code></pre>
  
  <p>But I don't know how to do cases-insensitive search using above line.</p>