replace callback function with matches
Solution 1:
The replace
function's callback takes the matches as parameters.
For example:
text = text.replace(/<wiki>(.+?)<\/wiki>/g, function(match, contents, offset, input_string)
{
return "<a href='wiki/"+contents.replace(/ /g, '_')+"'>"+contents+"</a>";
}
);
(The second parameter is the first capture group)