为什么regexp character \ 0与javaScript中的NULL html特殊字符match不匹配?

时间:2017-03-26 19:25:07

标签: javascript html regex null

为什么正则表达式字符\0(或\000)与我的文字中的html特殊字符�不匹配,而它与任何其他html特殊字符\001匹配得很好; \002 \044 $等?

var txtA = document.getElementById('textA').textContent;
var txtB = document.getElementById('textB').textContent;
var txtC = document.getElementById('textC').textContent;

var hasLineBreak = /\010|\n/g;
var hasNul = /\0|\00|\000/g;
var hasDollar = /\$|\044/g;

console.log("\\n: ",hasLineBreak.test(txtA));
console.log("\\0: ",hasNul.test(txtB));
console.log("$: ",hasDollar.test(txtC));
#textA{
  white-space: pre-wrap;
}

#textA, #textB, #textC{
  display:inline-block;
  border: solid 1px #33aaff;
  margin:4px;
}
<div id="textA">this is some &#010;text with line break</div>

<div id="textB">this is some text with &#000; null</div>

<div id="textC">this is some text with &#036; dollar sign</div>

0 个答案:

没有答案