replace callback function with matches

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="https://stackoverflow.com/questions/3395843/wiki/"+contents.replace(/ /g, "_')+"'>"+contents+"</a>";
    }
);

(The second parameter is the first capture group)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)