$(document)
returns a jQuery object, not a string. You need to call html()
to get the HTML contents of the document. You can do:
$('body').html(function(contents) {
return contents.replace(/regexp/, 'replacement');
});
If you just want to see the match:
var match = $('body').html().match(/regexp/);
console.log(match);