Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda