Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex case insensitivity

How would I make the following case insensitive?

if ($(this).attr("href").match(/\.exe$/))
{
// do something
}
like image 673
oshirowanen Avatar asked Oct 08 '10 12:10

oshirowanen


People also ask

Are regex matches case-sensitive?

In Java, by default, the regular expression (regex) matching is case sensitive.

What is case-insensitive matching?

Case insensitive matching is most frequently used in combination with the Windows file systems, which can store filenames using upper and lowercase letters, but do not distinguish between upper and lowercase characters when matching filenames on disk.

What does case-insensitive mean?

case insensitive (not comparable) (computer science) Treating or interpreting upper- and lowercase letters as being the same.


2 Answers

Put an i after the closing slash of the regex.

So your code would look like this:

if ($(this).attr("href").match(/\.exe$/i))
like image 116
Spudley Avatar answered Sep 22 '22 19:09

Spudley


With /i modifier:

if ($(this).attr("href").match(/\.exe$/i))
{
// do something
}
like image 45
Sarfraz Avatar answered Sep 23 '22 19:09

Sarfraz