Escaping back slash javascript through regex

Escaping back slash javascript through regex
0.0 0

#1

Hi, I am trying to escape backslash using regular expression in javascript. See this link please:
link. It does not show backslash in the console but it does in the return value. Is the back slash escaped or do I need to try any other way. Is it possible to escape backslash using regular expression because "replace function " does not seem to make a difference in output.

//Function
function abc(str){
	let regex = /\\/g;
	//str = str.replace(regex, "");
	console.log("str: ", str);
	return str;
}

//Tests
let str = "I can\'t do it. I don\'t know.";
abc(str);

#2

See what happens when you put "I can't" as the final line in the editor.


#3

I get I can\'t'. does that mean backslash is always there for special characters whether \ is added or not? but will not be printed .


#4

I think repl.it applies its own escaping when putting back user output.
For example, all string is in single quote form. So, to eliminate possible confusion, it chooses to escape any single quote inside the single quote string.


#5

It could be the reason. same results with chrome developer tool.
xx