How to make the regex not case sensitive?

by elise_daugherty , in category: Third Party Scripts , 7 days ago

How to make the regex not case sensitive?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 6 days ago

@elise_daugherty 

To make a regular expression (regex) not case sensitive, you can use the i flag after the regex pattern. For example, you can use the following syntax in JavaScript:

1
var regex = /pattern/i;


In this case, the i flag makes the regex pattern case insensitive, so it will match uppercase and lowercase letters without distinction.


Alternatively, you can also pass the i flag as a second argument when using the RegExp constructor:

1
var regex = new RegExp('pattern', 'i');


This will create a case-insensitive regex pattern as well.