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

162
Views
javascript, la subcadena debe excluir las etiquetas html en su recuento de caracteres

El substr no debe considerar las etiquetas html en su cuenta, ¿hay alguna forma de lograrlo?

por ejemplo, si tengo

 input = <p> This is testing <strong> hi </strong> how are you, Well doing </p>

El input.substring(0, 20) no debe considerar las etiquetas <p> y <strong> en su recuento de caracteres.

Las etiquetas html no deben eliminarse de la cadena, solo deben ignorarse en el recuento de la subcadena.

 <h2 v-html="this.$options.filters.limitText(input)" ></h2> filters: { limitText: function (val) { if(val && (val.length > 20)) { return (val.substring(0, 20).replace(/\s\S*$/, '') + ' ...') } return val; } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Esto ayuda?

 const input = "<p> This is testing <strong> hi </strong> how are you, Well doing </p>"; const tags = /<[^>]*>/g; const output = input.replace(tags, '').substring(0, 20); console.log(output); //-> ' This is testing hi'
about 4 years ago · Juan Pablo Isaza Report

0

Mi sugerencia:

 const input = "<p> This is testing <strong> hi </strong> how are you, Well doing </p>"; const count = input.replace(/(<([^>]+)>)/gi, "").length; console.log(count); // Output: 47
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!