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

215
Vistas
replace string in HTML doc after page loads

Ive a html doc with some markup like:

<p>Substance A, a metabolite enhances serotonergic production in neurons [33088927]. Substance B confers neuroprotection [28388366].  &nbsp;</p>

After the page loads Id like to find every occurrence in the document where there are square brackets and replace the string with something else, eg [33088927] -> 33088927i.

Using regex101.com Ive put together a function which finds the instances of square brackets:

function the_Pubs(){
    window.addEventListener("load", function(){
        const regex = /\[(.*?)\]/gm;
        let result;
            while((result = regex.exec(document.documentElement.outerHTML)) !== null) {
                if (result.index === regex.lastIndex) {
                        regex.lastIndex++;
                        }

        result.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
            
});
}
})}

How can I replace the found instances?

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

0

You can use String#replace with a callback function.

document.documentElement.innerHTML = document.documentElement.innerHTML
            .replace(/\[(.*?)\]/gm, (m, g) => g + "i");
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