我正在学习 Javascript 中的正则表达式,但有一件事我不明白。
以下正则表达式应匹配从 a 到 z 的任何字符串,但如果我添加一个数字,则表示这是正确的
var patron = /[a-zA-Z]/;
var regex = new RegExp(patron);
var v= "hello word 512";
if(v.match(regex))
{
//should not match but it does
}else
{
objInput.style.color = "red";
}
他们我试过这个:
var patron = /[a-zA-Z\D]/;
var regex = new RegExp(patron);
var v= "hello word 512";
if(v.match(regex))
{
//should not match but still dont work
}else
{
objInput.style.color = "red";
}
而且,括号不匹配
var patron = /[a-zA-Z\"\']/;
var regex = new RegExp(patron);
var v= "hello word 512";
if(v.match(regex))
{
//it match whenever the double quoute it followed by the single quoute'
}else
{
objInput.style.color = "red";
}