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

214
Views
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 answers
Answer question

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 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!