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

102
Visualizações
how to safely truncate text containing html tags with javascript

I have a string like this:

Hello world!<br />this is a new day for us<br /><br />lorem ipsum dolor and more long string here

and I need to only show the first 15 characters.. how do I do that? if possible I want to use only vanilla js (no jquery)

I thought of these steps:

  1. get rid of the html tags

  2. use substr to truncate the string

but some people says that using regex myString.replace(/<[^>]*>?/gm, ''); in javascript to strip html tags is not 100% dependable.. (link here) so now I don't know what to do. any help is appreciated

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