title: how to write a regex for a given string -Regex Javascript
body: <p>I am not so good at framing regex and I need help on this one:</p>
  
  <p>I want to do some regex on my string:</p>
  
  <pre><code>str= '(OS:"Windows" OR OS:"VMware") AND tags.tag.name:"test" and not asset:(name: "somename" or name="somename3" or name="somename4")';
  </code></pre>
  
  <p>we can ignore the key name and values here and focus on the format.</p>
  
  <p>with regex, I want the str to be replaced and new string to look like:</p>
  
  <pre><code>newStr= '(OS:"Windows" OR OS:"VMware") AND tags.tag:(name:"test") and not sev.name: "somename"'
  </code></pre>
  
  <p>so basically replace this part <code>tags.tag.name:"test"</code> with <code>tags.tag:(name:"test")</code> with regex.</p>
  
  <p>I tried this:</p>
  
  <pre><code>test = str.replace(/tags\.tag\.(([^&lt;&gt;=]+?\(.+?\))|.+?){1}($|(\s+?(and|or)\s+?))/ig, function(a, b, match2, match3, op) {
                      return String.format('{0}:({1}){2}', insert, b, op ? op:'');
                  });//here insert= '"tags.tag"'
  </code></pre>
  
  <p>but the o/p gives me:</p>
  
  <pre><code>"(OS:"Windows" OR OS:"VMware") AND tags.tag:(name:"test" AND not asset:(name: "somename" or name="somename3" or name="somename4"))"
  </code></pre>
  
  <p>which frames wrong query for me.</p>
  
  <p>HOw to achieve </p>
  
  <pre><code>newStr= '(OS:"Windows" OR OS:"VMware") AND tags.tag:(name:"test") and not sev.name: "somename"'
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>"(OS:"Windows" OR OS:"VMware") AND tags.tag:(name:"test" AND not asset:(name: "somename" or name="somename3" or name="somename4"))"
  </code></pre>
  
  <p>with the above regex?</p>
  
  <p>Thanks!</p>