I have the following code:
var key = "Force";
var phrase = "May the Force be with you";
I need to search for the key in phrase in a case-insensitive way.
It needs to be fast and reliable. I think a custom regex may be best here, but am not sure what is the best way to implement the same.
Any suggestions? What’s the best way to do this in JavaScript?
The
iflag is used for case-insensitive search:You can learn more at the Mozilla docs for the search function and regular expressions.
You can also test your regular expressions (minus JavaScript specific features) at regexpal.