Let's see some examples of using the methods search() and match(). First, you create a string object.
var s = new String('HelloJavaScriptWorld');
Using match() you get an array containing only the first match:
s.match(/a/); ["a"]
Using the g modifier, you perform a global search, so the result array contains two elements:
s.match(/a/g); ["a", "a"]
Case insensitive match:
s.match(/j.*a/i); ["Java"]
The search() method gives you the position of the matching string:
s.search(/j.*a/i); 5