What is the difference between indexOf() and search()?

If you require a regular expression, use search(). Otherwise, indexOf() is going to be faster.


indexOf is for plain substrings, search is for regular expressions.


The search function (one description here) takes a regular expression, which allows you to match against more sophisticated patters, case-insensitive strings, etc., while indexOf (one description here) simply matches a literal string. However, indexOf also allows you to specify a beginning index.