167
![Stack Overflow](http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png)
The RegExp object keeps track of the lastIndex where a match occurred, so on subsequent matches it will start from the last used index, instead of 0. Take a look:
var query = 'Foo B';
var re = new RegExp(query, 'gi');
var result = [];
result.push(re.test('Foo Bar'));
alert(re.lastIndex);
resul...