You can use this regular expression to match markdown links:
\[(.*?)\]\(.*?\)
Explanation:
\[
and\]
match a literal open and close bracket.(.*?)
matches any character (.
), repeated any number of times (*
) but as few as possible (?
). The brackets create a capture group.\(
and\)
match a literal open and close parenthesis..*?
matches any character, repeated any number of times but as few as possible.
Then you can use the first capture group $1
to replace the matched link with the text content.
In JavaScript, you can apply this regex using str.replace()
function:
let str = "[personal information you disclose to us](https://www.notion.so/667877d1f5a1485ca078dbffc3ad42c3?pvs=21)."
let newStr = str.replace(/\[(.*?)\]\(.*?\)/g, "$1");
In the example above, newStr
will be:
"personal information you disclose to us."