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)
Any Ideas?
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)
Any Ideas?
Share Improve this question edited Apr 21, 2011 at 13:19 T.J. Crowder 1.1m199 gold badges2k silver badges1.9k bronze badges asked Apr 21, 2011 at 13:12 NirNir 2,6299 gold badges47 silver badges75 bronze badges 10 | Show 5 more comments1 Answer
Reset to default 37The i
flag you have on the end (/.../i
) should be doing it.
(CW because let's face it, one shouldn't earn rep for this sort of thing... :-) )
i
at the end of the regex makes it case-insensitive. – Felix Kling Commented Apr 21, 2011 at 13:15.
in the question, but I did not. I just highlighted the code and clicked the{}
button. @user: I've just gone and removed it again. If that backslash is in your code, you can go back and edit it back in.</s> The backslash was there, it's just that since it wasn't formatted as code, it wasn't showing. whew @user: This demonstrates the value of formatting the code, to avoid misunderstandings (@KooilInc's answer is based on that misunderstanding). – T.J. Crowder Commented Apr 21, 2011 at 13:19