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

418
Views
Cómo eliminar todas las etiquetas html, incluido ' ' de cuerda?

He usado CKEDITOR en uno de mis módulos. Almacena datos con etiquetas HTML como a continuación:

 <p>Lorem Ipsum&amp;nbsp;is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry&amp;#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>\n\n<p>&nbsp; </p>\n\n<p>TItle&nbsp;</p>\n

He intentado convertir en texto sin formato usando esta expresión regular:

 str.replace(/(<([^>]+)>)/ig ,'');

Sin embargo, no obtengo el resultado esperado.

Quiero esta salida:

'Lorem Ipsum & es simplemente texto ficticio de la industria de la impresión y la composición tipográfica. Lorem Ipsum ha sido el texto ficticio estándar de la industria desde el siglo XVI, cuando un impresor desconocido tomó una galera de tipos y la codificó para hacer un libro de muestras tipográficas. Ha sobrevivido no solo cinco siglos, sino también el salto a la composición tipográfica electrónica, permaneciendo esencialmente sin cambios. Se popularizó en la década de 1960 con el lanzamiento de hojas de Letraset que contenían pasajes de Lorem Ipsum y, más recientemente, con software de autoedición como Aldus PageMaker, que incluía versiones de Lorem Ipsum.TItle.

Nota: esta expresión regular elimina todas las etiquetas html excepto "\n, &nbsp" . Así que, por favor, ayúdenme... ¿Cómo eliminar "\n, &nbsp" también de la cadena?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El texto parece tener doble escape, algo así: primero gire todos los &amp; s en & s, para que las entidades HTML puedan reconocerse correctamente. Entonces .text() le dará la versión de texto sin formato del marcado HTML.

 const input = `<p>Lorem Ipsum&amp;nbsp;is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry&amp;#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>\n\n<p>&nbsp;</p>\n\n<p>TItle&nbsp;</p>\n`; const inputWithProperEntities = input.replaceAll('&amp;', '&'); console.log($(inputWithProperEntities).text());
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

\n no es una etiqueta HTML, sino la representación de un carácter de nueva línea. Si también desea eliminar todas las líneas nuevas, entonces:

 const input = `<p>Lorem Ipsum&amp;nbsp;is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry&amp;#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>\n\n<p>&nbsp;</p>\n\n<p>TItle&nbsp;</p>\n`; const inputWithProperEntities = input.replaceAll('&amp;', '&'); console.log($(inputWithProperEntities).text().replaceAll('\n', ''));
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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!