title: Jquery replacing image url with html element
body: <p>So I have this code</p>
  <pre class="lang-js prettyprint-override"><code>let data.message = &quot;message https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png&quot;
  
  $('&lt;div/&gt;').text(data.message).html().replace(/((http|https|ftp):\/\/[\w?=&amp;.\/-;#~%-]+(?![\w\s?&amp;.\/;#~%&quot;=-]*&gt;))/g, '&lt;img src=&quot;$1&quot;&gt;$1&lt;/a&gt; ')
  </code></pre>
  <p>Idk why its not working it splits the line on my thing cause its a chat app but it splits the http s:// for some reason heres the code to go to next line:</p>
  <pre class="lang-js prettyprint-override"><code>
  function getName(name) {
    let newName = name;
    // offsets i to match the current string
    let offset = 0;
  
    for (let i = 1; i &lt; name.length; i += 1) {
      if (i % 35 === 0) {
        if(newName.charAt(i) === ' ') {
          // Your own code with the offset
          newName = newName = `${newName.substr(0, i - offset)}\n${newName.substr(i - offset + 1)}`;
        } else {
          // looking back in the string until there is a space or the string &quot;ends&quot;
          while(newName.charAt(i - offset) !== ' ' &amp;&amp; offset &lt;= 35) {
            offset++;
          }
  
          // Only set newName if a space was found in the last 35
          if(i - offset &gt; 0) {
            newName = `${newName.substr(0, i - offset)}\n${newName.substr(i - offset + 1)}`;
          }
        }
      }
    }
  
    return newName;
  }
  </code></pre>