title: How to replace host part of a URL using javascript regex
body: <p>How to replace the <strong>host part</strong> of a URL using javascript regex. This can be any kind of URL with or without http. Assume this text is from the content of a json file. </p>
  
  <p>OldText: </p>
  
  <pre><code>{
     "auth" : {
       "login" : "http://local.example.com:85/auth/signin",
       "resetpass" : "http://local.example.com:85/auth/resetpass",
       "profile" : "http://local.example.com/auth/profile"
     }
  }
  </code></pre>
  
  <p>Expecting a solution like: </p>
  
  <pre><code>var NewText = OldText.replace (/(some regex)/g, 'example.com');
  </code></pre>
  
  <p>To get NewText as: </p>
  
  <pre><code>{
    "auth" : {
       "login" : "http://example.com:85/auth/signin",
       "resetpass" : "http://example.com:85/auth/resetpass",
       "profile" : "http://example.com/auth/profile"
      }
  }
  </code></pre>
  
  <p>I found the same <a href="https://stackoverflow.com/questions/26306968/simple-regex-to-replace-first-part-of-url">here</a>, but that regex won't work in javascript. </p>
  
  <p>Note: I'm looking for the Regex. </p>