I think the purpose for regex is much different from indexOf
.indexOf
simply find the occurance of a certain string while in regex you can use wildcards like [A-Z]
which means it will find any capital character in the word without stating the actual character.
Example:
var index = "This is a string".indexOf("is"); console.log(index); var length = "This is a string".match(/[a-z]/g).length; // where [a-z] is a regex wildcard expression thats why its slower console.log(length);