我一直在研究文本到 ASCII 文本转换器。这是代码:
(function (i , code) {
var inputs = code.getElementsByTagName("textarea"),
text = inputs[0],
binary = inputs[1],
tran2 = /\s*[01]{8}\s*/g,
e = /[\s\S]/g,
f = /^(\s*[01]{8}\s*)*$/,
r = /^[\x00-\xff]*$/,
n = String.fromCharCode;
ASC = '!"#$%&' + "'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
function m(s) {
return "00000000".slice(String(s).length) + s
}
function change(s) {
return s.replace(tran2, function (t) {
return n(parseInt(t, 2))
})
}
function change2(s) {
return s.replace(e, function (t) {
return m(t.charCodeAt().toString(2)) + ' '
})
}
function h(object, regExp, func, SecObj) {
var GotValue = object.value,
s = "";
if (regExp.test(GotValue)) {
SecObj.value = s = func(GotValue);
object.className = SecObj.className = ""
} else {
SecObj.value = "ERROR: invalid input";
object.className = SecObj.className = "invalid"
}
return x == text ? GotValue : s
}
function primary() {
var s = this == binary ? h(binary, f, change, text) : h(text, r, change2, binary);
}
text.onkeyup = binary.onkeyup = primary;
text.oninput = binary.oninput = function () {
text.onkeyup = binary.onkeyup = null;
primary.call(this)
};
}(this, document));
ThatWill 将 taxt 转换为二进制并返回。出现错误时,我想查找不匹配的字符
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
有没有人不知道我怎么能用 reg exp 做到这一点?