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

226
Vistas
Remove HTML tags but implement line breaks from text (Regex and Javascript)

I have a paragraph of text coming from the backend that has
within curly brackets like so:

...some text { <br /> } { <br /> } ...more text

and some inline HTML styling like:

...some text <strong>some text</strong>

I need to remove all of these but need break where the line breaks are.

How can these be done with Regex?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have a solution that doesn't require regex. However, since I don't know the content of your html, it might NOT work well. So, test it to make sure.

The first part is a simple text replace, so it doesn't require regex

htmlData.replaceAll('{ <br /> } ', '\n');

Then, you create a DOM element, insert all the html data into it, and get the innerText attribute that is the text data without the tags.

const p = '...some text <strong>some text</strong> more text <b>more</b> text...some text { <br /> } { <br /> } ...more text';
console.log("BEFORE: "+p);

let tmp = document.createElement("DIV");
// Replace into newlines.
tmp.innerHTML = p.replaceAll('{ <br /> } ', '\n');
// Get the text.
console.log("AFTER: "+tmp.innerText);

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