Javascript匹配正则表达式链接

mff*_*fap 2 javascript regex

嗨我在div中有以下文字:

[http://www.google.com Google this link] some other random text [http://example.com and another website] but don't parse [this is not a link, leave me alone].
Run Code Online (Sandbox Code Playgroud)

我试图做的是将链接转换为正常的HTML链接.格式总是这样,所以它打开[然后是网址,然后是链接文本,然后是关闭].但我只想匹配链接,而不是方括号中的所有文本.

我想.match()在javascript中使用函数来完成这个任务,但是我无法弄清楚正则表达式(我只需要链接的文本部分 - 其余部分应该是简单的拆分).

任何帮助都会受到影响.

Max*_*Art 5

为什么.match.replace呢?

string.replace(/\[(https?:\/\/[^\]\s]+)(?: ([^\]]*))?\]/g, "<a href='$1'>$2</a>");
Run Code Online (Sandbox Code Playgroud)