You can get the link text (or rather link content, as links can contain other elements) via .textContent. I’ve set up a complete example here:
String.matchAll() is still a proposal, and support is spotty. A compatible implementation might look like this:
function getLinks(text) {
const pattern = /\[(?<text>.+?)\]\((?<href>.+?)\)/g, matches = [];
let m;
while(m = pattern.exec(text)) matches.push(m.groups);
return matches;
}
This version uses named capture groups, so that the returned array will look something like this:
[{text: "My link text", href: "http://example.com"}, ...]