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

191
Views
Javascript regexp not replacing/matching

I want to remove the regex content from my string but it works on the regex site (https://regex101.com/r/XSpa6d/2) but not with my code. What did I do wrong cuz cant seem to find it? (https://jsfiddle.net/eL8r4b1j/)

const string = "random characterhundsguhiosdg window.__AH_DATA__= {gert}\n\n  window.__APOLLO_STATE__= {} random characterhundsguhiosdg"
const r = new RegExp(/window\.__AH_DATA__= {.*}\\n\\n  window\.__APOLLO_STATE__= {}/gm)
const replaced = string.replace(r, "")
console.log(replaced)

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

0

New lines should not be double escaped.

const string = "random characterhundsguhiosdg window.__AH_DATA__= {gert}\n\n  window.__APOLLO_STATE__= {} random characterhundsguhiosdg"
const r = new RegExp(/window\.__AH_DATA__= {.*}\n\n  window\.__APOLLO_STATE__= {}/gm)
const replaced = string.replace(r, "")
console.log(replaced)

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!