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

181
Vistas
How to find a word with HTML tags inside

I am trying to solve this problem on typescript (Angular 12):

I want to find the word tempor in the following string (tempor is just an example, can be any word):

<p>Lorem ipsum dolor sit <em>amet</em>, consectetur adipiscing elit, sed do eiusmod te<b>m</b>por incididunt ut labore et dolore magna aliqua.</p>

The problem is that the word can contains any html code inside, Ex: te<b>m</b>por, <em>tem</em>por , tem<a>por<a/>, etc.

Also, I cannot use regular expressions, because a word can contain any html inside and we consider an infinite number of words that the user can enter, therefore it is not possible to use regular expressions as a pattern.

I was looking for some npm but couldn't find anything that can solve the problem.

In short, I need to find the word without the html tags, but I need to also preserve the html in terms of representing the style, some business rules, etc.

Does anyone know how to solve it or do you know an npm that can help me?

Thanks in advance.

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

0

element.textContent gives you only text without tags. You can find your desired string: element.textContent.indexOf('tempor') !== -1

about 4 years ago · Juan Pablo Isaza Denunciar

0

enter image description here

You can try this way.

let text = document.querySelector('p')?.textContent;
console.log(text?.search('tempor'));//72
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