如何使正则表达式不区分大小写? [英] How to make regex case-insensitive?

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

问题描述

我有这个javascript代码但是当我发送这个:asd.JPG时,正则表达式对我失败..

I have this javascript code but when i send this: asd.JPG the regex fails to me..

if (data.match(/([^\/\\]+)\.(jpg|jpeg|gif|png|tiff|tif)$/i))
     return { filename: RegExp.$1, ext: RegExp.$2 };
else
     return { filename: "invalid file type", ext: null };

所以我希望正则表达式将扩展名视为不区分大小写。
我尝试了这个但它失败了:

So I want that the regex looks at the extension as case-insensitive. I tried this but it fails:

data.match(/([^\/\\]+)\.(?i)(jpg|jpeg|gif|png|tiff|tif)$/i)

任何想法?

推荐答案

i 标志你有最后的结果( /.../ i )应该这样做。

The i flag you have on the end (/.../i) should be doing it.

(CW因为我们的面对它,人们不应该为这种事情赢得代表...... :-))

(CW because let's face it, one shouldn't earn rep for this sort of thing... :-) )

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

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