Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!