I'm trying to use regex to convert Slack's version of markdown formatting to BB Code. I'm stuck on links at the moment. Slack formats like this:
<www.url.com|This is the actual text>
<www.url.com>
BB Code formats like this:
[url=www.url.com]This is the actual text[/url]
[url]www.url.com[/url]
I'm dealing with the first type using this (in javascript)
string.replace(/\<([\s\S]+)(?=\|)\|([\s\S]*?)\>/gm, "[url=$1]$2[/url]"
I'm struggling to make a second rule that will only match text between <...>
if there isn't a |
in the string. Can anyone help me out?
Also if there's a neat way of dealing with both options in one go then let me know!