Basic usage:

1. Regular expression object approach:


var pattern = /var/;
var str = "var x = 100;";
var hasMatches = pattern.test(str); // boolean
var matches = pattern.exec(str); // array

2. String approach:


var patternstr = "var";
var str = "var x = 100;";
var matches = str.match(patternstr); // array
Advertisements