Why can’t regular matching capture the “\” backslash?

  node.js, question
var str = "\abc";  //The string is obtained and cannot be changed to \\abc
 var re = /^\abc/;
 console.log(re.test(str));  //true
 console.log(str.match(re));
 //["abc", index: 0, input: "abc"] does not have' \'
 console.log(re.exec(str));
 //["abc", index: 0, input: "abc"] does not have' \'
 
 
 var re2 = /^\\abc/;
 console.log(re2.test(str));  //false
 console.log(str.match(re2));  //null
 console.log(re2.exec(str));  //null
 
 var re3 = /^\\\abc/;
 console.log(re3.test(str));  //false
 console.log(str.match(re3));  //null
 console.log(re3.exec(str));  //null
 
 var re4 = /^\\\\abc/;
 console.log(re4.test(str));  //false
 console.log(str.match(re4));  //null
 console.log(re4.exec(str));  //null

The backslash “\” is an escape character. If it appears before the character, then they are a whole. For example, “n” means a newline character.
To verify what I said above, you can try the following line of code:

var str = "\abc";
 console.info(str.length);  // 3

The result is 3, indicating that’ \a’ is a character.
If you want to indicate’ \’ in the string, you have to escape it and add a backslash’ \ \’ to it.
Therefore, the code above should read as follows:

var str = "\\abc";
 var re = /^\\abc/;
 console.log(re.test(str));  //true
 console.log(str.match(re));  // ["\abc", index: 0, input: "\abc"]