• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

160
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error