I have the following problem that I'm trying to solve with String.replace:
I have a random text that contains IDs of tickets in some system e.g. JIRA-123. I want to replace then with Markdown links like so:
text.replace(/(JIRA-\d+)/g, "[$1](example.com?id=$1)");
The problem I'm struggling with is that I want this operation to be idempotent i.e. if a given ID is already wrapped in the URL I want it to be ignored and I'm struggling to figure out a correct expression to achieve that.
Any help?
generateLink("$1")is not working.s.replace(/(p1)|p2/g, (x,y) => y ? x : process(x)))/(JIRA-\d+)/gexpression fit in this solution?