Javascript 如何使正则表达式匹配大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7411194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make a regular expression match upper and lower case?
提问by SoulieBaby
I don't really know much about regex at all, but if someone could help me change the following code to also allow for lowercase a-z, that would be great!
我对正则表达式一无所知,但如果有人能帮我更改以下代码以允许小写 az,那就太好了!
$("input.code").keyup(function(){
this.value = this.value.match(/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/)[0];
});
回答by cheeken
回答by Benjamin Udink ten Cate
/[A-Za-z]{3}([0-9]{1,4})?|[A-Za-z]{1,3}/
[]
denotes a character class and A-Z
is a allowed range and means ABCDEFGHIJKLMNOPQRSTUVWXYZ. You can extend this easy by adding a-z
[]
表示一个字符类,A-Z
是一个允许的范围,表示 ABCDEFGHIJKLMNOPQRSTUVWXYZ。您可以通过添加来轻松扩展a-z