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 th
I think all the previous answers are correct. Here is another example similar to SERPRO's, but the difference is that there is no new constructor:
Notice: i ignores the case and ^ means "starts with".
var whateverString = "My test String";
var pattern = /^my/i;
var result = pattern.test(whateverString);
if (result === true) {
console.log(pattern, "pattern matched!");
} else {
console.log(pattern, "pattern did NOT match!");
}
Here is the jsfiddle (old version) if you would like to give it a try.