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