I had tried to get the link from the text using below code
urlify(description) {
const regex = /(.+)\[(.+)\]\((.+)\)/;
return description.replace(regex, (match, a, b, c) => {
const text = `${a[0].toUpperCase()}${a.substring(1)}${b}`;
return a+' '+`<a href="${c}" target="_blank">${b}</a>`;
});
}
render() {
let description='Hello this is [XYZ](wwww.XYZ.com) and please redirect to [PQR]
(www.PQR.com)'
return (
<p dangerouslySetInnerHTML={{__html: this.urlify(description),}}></p>
);
}
}
The output I get here is like
Hello this is XYZ and please redirect to PQR Only the last link is getting as required, I am trying something like 'Hello this is XYZ and please redirect to PQR' where XYZ and PQR should only act as link and (wwww.XYZ.com), (www.PQR.com) such link should act as href only.