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

74
Vistas
Multiple Regex on a single request

I wrote an app that shows last posts through API, and I'm using a regex to strip HTML tags from the result (that is actually plain text).

post.contentHtml retrieve the last post

example retrieved: "hi this is my last post <b>with</b> some html tags"

so my line is:

 post.contentHtml().replace(/<\/?[^>]+(>|$)/g, '')

example retrieved: "hi this is my last post with some html tags"

Now sometimes users post text with image URLs, and I want to replace all image URLs with a FontAwesome icons.

Is this possible with JavaScript?

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

0

found a solution by myself:

since i do not know how to replace with rendered html (actually if i put html it returns literally, i can do this with a text icon:

post.contentHtml().replace(/<\/?[^>]+(>|$)/g, '').replace(/(https?:\/\/\S+(\.png|\.jpg|\.gif))/g, '📷')
about 4 years ago · Juan Pablo Isaza Denunciar

0

The simplest solution is to use match with regex. The sample is given below.

Regex: /<[^>]*>/g

Note: You can make a more complex regex.

const str = 'hi this is <img src="test" /> my  <span>with1</span> last post <b>with2</b> some html tags';
console.log(str.replace(/<[^>]*>/g, ""))

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