I have below description, which I am trying to replace the links in href
props with signed s3 links on the backend without DOM
So, I need to first loop over all the matching s3 links and replace it with signed one.
The problem is It replaces other parts as well. It doesn't know when to end the matching.
Here is what I am trying to do,
- Collect all the links
- Filter links which has s3 related keyword
- replace them with signed s3 link
function replaceNonSignedS3WithSignedLink(text) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
return 'https://signed-s3-link.com';
})
// or alternatively
// return text.replace(urlRegex, '<a href="$1">$1</a>')
}
const desc = `<h3>Introduction Session</h3><p>Monday, March 3, 2021 11:00AM - 01:00PM</p>
Click <a href='https://example.s3.amazonaws.com/assets/bio.pdf'>here</a>`;
const result = replaceNonSignedS3WithSignedLink(desc);
console.log(result)
The result I get is,
"<h3>Introduction Session</h3><p>Monday, March 3, 2021 11:00AM - 01:00PM</p>
Click <a href='https://signed-s3-link.com"