如何使正则表达式匹配大小写? [英] How can I make a regular expression match upper and lower case?

查看:70
本文介绍了如何使正则表达式匹配大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对正则表达式一点也不了解,但是如果有人可以帮助我更改以下代码以允许使用小写字母a-z,那就太好了!

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!

$("input.code").keyup(function(){
    this.value = this.value.match(/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/)[0];
});

推荐答案

如果您希望正则表达式不区分大小写,请添加 i

If you want a regular expression to be case-insensitive, add a i modifier to the end of the regex. Like so:

/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/i

这篇关于如何使正则表达式匹配大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆