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

159
Views
How to get only text from string, ignoring tags

Let's say i have this string :

<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??">This is only<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??"> <img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">what i want<img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">

I need to extract only the part of the text without the <img tag. In the example above, this is the resuilt i need :

This is only what i want

Is there a fast / simple way to do this, without having to loop the entire string and manually replacing things ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use DOM?

const str = `<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??">This is only<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??"> <img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">what i want<img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">`
const div = document.createElement("div");
div.innerHTML = str
console.log(div.textContent)

about 4 years ago · Juan Pablo Isaza Report

0

The following regular expression:

/(?<=\>)([^\<][\s\w]{1,})/gm

will do this for you. See below:

let str = '<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??">This is only<img class="emoji emoji-small" src="./img-apple-64/1f525.png" alt="??"> <img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">what i want<img class="emoji emoji-small" src="./img-apple-64/1f916.png" alt="??">'

let match = str.match(/(?<=\>)([^\<][\s\w]{1,})/gm);

match is an array containing the values ['This is only', 'what I want']

about 4 years ago · Juan Pablo Isaza Report
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!