Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Jquery replacing image url with html element

So I have this code

let data.message = "message https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png"

$('<div/>').text(data.message).html().replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '<img src="$1">$1</a> ')

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:


function getName(name) {
  let newName = name;
  // offsets i to match the current string
  let offset = 0;

  for (let i = 1; i < 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 "ends"
        while(newName.charAt(i - offset) !== ' ' && offset <= 35) {
          offset++;
        }

        // Only set newName if a space was found in the last 35
        if(i - offset > 0) {
          newName = `${newName.substr(0, i - offset)}\n${newName.substr(i - offset + 1)}`;
        }
      }
    }
  }

  return newName;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!