Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda