Я чувствую, что меня обманули, но, проверяя ОП в моем браузере, я получаю ...
<p>The actual resolution of this image is 3067x2276, not 4381x3251. See <a href="https://www.reddit.com/r/EarthPorn/wiki/index#wiki_resolution.3F_what_is_that_and_how_can_i_find_it.3F" rel="nofollow noreferrer">this</a> page for information on how to find out what the resolution of an image is.</p>
Другими словами, если вы найдете [words](URL)
, замените его на:
<a href="URL">words</a>
Это маленькое регулярное выражение пытается захватить содержимое [], а затем ().Проверка http может быть недостаточной в зависимости от того, какие ссылки вы ожидаете ...
let regex = /\[(.*?)\]\(([^\)]+)\)/g;
let matches = regex.exec(line);
// matches ought to contains words and a potential url
if (matches.length > 2 && matches[2].startsWith("http://")) {
// matches[2] is probably a url, so...
let replace = `<a href="${matches[2]}">${matches[1]}</a>`
// ...
}