var str = "\abc";// 字符串是獲取到的,不能更改為了\\abcvar re = /^\abc/;console.log(re.test(str));//trueconsole.log(str.match(re));//["abc", index: 0, input: "abc"] 沒有'\'console.log(re.exec(str));//["abc", index: 0, input: "abc"] 沒有'\'var re2 = /^\\abc/;console.log(re2.test(str));//falseconsole.log(str.match(re2));//nullconsole.log(re2.exec(str));//nullvar re3 = /^\\\abc/;console.log(re3.test(str));//falseconsole.log(str.match(re3));//nullconsole.log(re3.exec(str));//nullvar re4 = /^\\\\abc/;console.log(re4.test(str));//falseconsole.log(str.match(re4));//nullconsole.log(re4.exec(str));//null
為何正則匹配捕獲不了“\”反斜杠?
互換的青春
2018-08-08 11:11:19