How would I make the following case insensitive?
if ($(this).attr("href").match(/\.exe$/))
{
// do something
}
How would I make the following case insensitive?
if ($(this).attr("href").match(/\.exe$/))
{
// do something
}
Put an i
after the closing slash of the regex.
So your code would look like this:
if ($(this).attr("href").match(/\.exe$/i))
With /i
modifier:
if ($(this).attr("href").match(/\.exe$/i))
{
// do something
}
Another option would be to simply manipulate the case to what you want.
It appears as though you are trying to match against lowercase characters.
So you could do this:
if ($(this).attr("href").toLowerCase().match(/\.exe$/)) {
// do something
}
In fact, you could use .indexOf()
instead of a regex if you wanted.
if ($(this).attr("href").toLowerCase().indexOf('.exe') > -1) {
// do something
}
Of course, this would match .exe
in the middle of the string as well, if that's an issue.
Finally, you don't really need to create a jQuery object for this. The href
property is accessible directly from the element represented by this
.
if ( this.href.toLowerCase().match(/\.exe$/) ) {
// do something
}