I'm trying to get the URL and link text from these 2 types of URLs:
<a href="http://www.example.com">Example</a>
<a href="http://www.example.com" rel="nofollow">Example</a>
At first I had this:
text = text.replace(/<a href="(.*)">(.*)<\/a>/gim, "[$2]($1)");
But that includes rel="nofollow"
in $2
for the 2nd example. I changed it to:
text = text.replace(/<a href="(.*)"( rel=".*"{0,})>(.*)<\/a>/gim, "[$3]($1)");
Now, the rel="nofollow"
link is perfect, but the first example isn't matched at all.
{0,}
should mean "match rel=".*"
0 or more times".
What am I doing wrong?