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

211
Vistas
Is there any way to remove the "Code Snippet" from a string?

Let's say I have figure tags in a string

const content = 'Here is a sentence followed up with <figure><img /></figure> plus some more text.'

Is there a way I can check to see if there is a figure tag in the string, select the tags and all of its contents, and remove or filter out all of them with React or Javascript?

The desired output would be

const content = 'Here is a sentence followed up with plus some more text.'

I know it is not clean but it supports an Algolia query.

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

0

You can use RegEx for this. One possible RegEx would be /(<figure>.+<\/figure>)/g (https://regexr.com/6ke0o)

So some sample code would look like this:

const content = 'Here is a sentence followed up with <figure><img /></figure> plus some more text.'.replace(/(<figure>.+<\/figure>)/g, '')
about 4 years ago · Juan Pablo Isaza Denunciar

0

if you only want to remove tags (NOT tag body):

console.log("Here is a sentence followed up with <figure><img /><\figure> plus some more text.".replaceAll(/<\\?[a-zA-Z\s]+\/?>/g,""))

or:

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

if you want to just remove figure tag:

console.log("Here is a sentence followed up with <figure><img/><\figure> plus some more text.".replaceAll(/<figure>.+<\figure>/g,""))

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use the DOM parser, create an element, put your content in as innerHTML, and filter the childNodes so that only text nodes remain.

const content = 'Here is a sentence followed up with <figure><img /></figure> plus some more text.'

const tester = document.createElement('div');
tester.innerHTML = content;

const output = [...tester.childNodes].filter(child => child.nodeType === 3).map(child => child.nodeValue.trim()).join(" ");

console.log(output);

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