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

88
Views
How to replace a full console logs with preceding whitespaces and possible new line from string with regex

I need to replace a console.log('') construction in a string using regex. Before the console log there can be random number of whitespaces and one or zero new line characters '\n'. I want to delete it together with the console log. Here is my code:

const consoleRegex = new RegExp(/\\n?\s+console\.log\(.*\);?/);
let v = "<script>\n  console.log('test');\n</script>"

v = v.replace(consoleRegex, '');

The desired result is <script>\n</script>. When I test the regex in the tester it works however it does not get replaced.

Thanks

about 4 years ago · Juan Pablo Isaza
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!