var pattern = new RegExp(/^\s+(.+?)\s+$/);
var str = ' google google ';
alert(pattern.exec(str)[1]);
var pattern = new RegExp(/^\s+$/);
var str = ' bb baidu google ';
alert(str.replace(pattern,''));
var pattern = new RegExp(/^\s+(.+?)\s+$/);
var str = ' google google ';
alert(pattern.exec(str)[1]);
var pattern = new RegExp(/^\s+$/);
var str = ' bb baidu google ';
alert(str.replace(pattern,''));