title: MongoDB regex replace
body: <p>My table name is : table_video
  My field name in db is : url_value</p>
  
  <p>Whose value is : <a href="http://192.168.1.124/test/" rel="nofollow">http://192.168.1.124/test/</a><strong>abcd</strong>/<strong>abcd</strong>.m3u8</p>
  
  <p>Value which is needed by me : <a href="http://192.168.1.124/test/" rel="nofollow">http://192.168.1.124/test/</a><strong>abcd_NEW</strong>/<strong>abcd_NEW</strong>.m3u8</p>
  
  <p>There are multiple values in place of "abcd", above url is just one example.</p>
  
  <pre><code>var cursor = db.table_video.find();
  while (cursor.hasNext()) {
    var x = cursor.next();
    print("\n\n-----------------------------------");
  
    print("Before : url_value : "+x['url_value']);
  
    x['url_value'] = x['url_value'].replace(/^(.*?)\/test\/(.*?)\/(.*?)\.m3u8$/g, $1/test/$2_NEW/$2_NEW.m3u8);
  
    print("After : url_value : "+x['url_value']);
  
    db.table_video.update({_id : x._id}, x);
  
  }
  </code></pre>
  
  <p>When I execute above command in mongo console, it gives an error : 2015-11-28T12:40:08.342+0530 ReferenceError: $1 is not defined</p>
  
  <p>Any help is greatly appreciated</p>