Sometimes, we want to create a case insensitive regex in JavaScript.
In this article, we’ll look at how to create a case insensitive regex in JavaScript.
How to create a case insensitive regex in JavaScript?
To create a case insensitive regex in JavaScript, we can use the i flag.
For instance, we write
const value = "some text with dAtE";
const hasDate = /date/i.test(value);
to create the /date/i regex which matches 'date' with the letters in any case.
And then we call test on it with value to match 'dAtE'.
Conclusion
To create a case insensitive regex in JavaScript, we can use the i flag.
