I need to check whether a word starts with a particular substring ignoring the case differences. I have been doing this check using the following regex search pattern but that does not help when there is difference in case across the strings.
my case sensitive way:
var searchPattern = new RegExp('^' + query); if (searchPattern.test(stringToCheck)) {}
Advertisement
Answer
Pass the i
modifier as second argument:
new RegExp('^' + query, 'i');
Have a look at the documentation for more information.